AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to store a pronunciation lexicon in an AWS Region.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. from argparse import ArgumentParser from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # Define and parse the command line arguments cli = ArgumentParser(description="PutLexicon example") cli.add_argument("path", type=str, metavar="FILE_PATH") cli.add_argument("-n", "--name", type=str, required=True, metavar="LEXICON_NAME", dest="name") arguments = cli.parse_args() # Create a client using the credentials and region defined in the adminuser # section of the AWS credentials and configuration files session = Session(profile_name="adminuser") polly = session.client("polly") # Open the PLS lexicon file for reading try: with open(arguments.path, "r") as lexicon_file: # Read the pls file contents lexicon_data = # Store the PLS lexicon on the service. # If a lexicon with that name already exists, # its contents will be updated response = polly.put_lexicon(, Content=lexicon_data) except (IOError, BotoCoreError, ClientError) as error: # Could not open/read the file or the service returned an error, # exit gracefully cli.error(error) print(u"The \"{0}\" lexicon is now available for use.".format(

Sample Details

Service: polly

Last tested: 2019-01-31

Author: (AWS)

Type: full-example

On this page: