本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeleteLexicon
以下 Python 代码示例使用AWS SDK for Python (Boto) 删除在本地 AWS 配置中指定的区域中的词典。该示例只删除指定的词典。在实际删除词典前,它会要求您确认要继续操作。
以下代码示例使用存储在 AWS 软件开发工具包配置文件中的默认凭证。有关创建配置文件的信息,请参阅 设置 AWS CLI。
有关此操作的更多信息,请参阅 DeleteLexicon
API 参考。
from argparse import ArgumentParser from sys import version_info from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # Define and parse the command line arguments cli = ArgumentParser(description="DeleteLexicon example") cli.add_argument("name", type=str, metavar="LEXICON_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") # Request confirmation prompt = input if version_info >= (3, 0) else raw_input proceed = prompt((u"This will delete the \"{0}\" lexicon," " do you want to proceed? [y,n]: ").format(arguments.name)) if proceed in ("y", "Y"): print(u"Deleting {0}...".format(arguments.name)) try: # Request deletion of a lexicon by name response = polly.delete_lexicon(Name=arguments.name) except (BotoCoreError, ClientError) as error: # The service returned an error, exit gracefully cli.error(error) print("Done.") else: print("Cancelled.")