python-3.x - Boto3 InvalidParameterException 在执行 lambda 函数时
问题描述
我在运行 lambda 函数时收到 Boto3 InvalidParameterException。我试图找到一种方法来处理这个异常。
我遇到了以下解决方案:
from boto.exception import BotoServerError
class InvalidParameterException(BotoServerError):
pass
我正在使用 python3 并了解 boto 现在已弃用并被 boto3 取代。但我在 boto3 中找不到等效的解决方案。
谁能帮我解决这个问题?
解决方案
正如boto
已弃用的那样modeled
,客户端上的所有异常都可用。您也可以在 API 文档中查找相同的内容,基本上代码boto3
是直接从 API 生成的。早期的方法boto
是硬编码的东西并为此编写代码。
正如你在这里看到的
例如
import boto3
from botocore.exceptions import ClientError
def get_secret():
secret_name = "MySecretName"
region_name = "us-west-2"
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name,
)
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
if e.response['Error']['Code'] == 'ResourceNotFoundException':
print("The requested secret " + secret_name + " was not found")
elif e.response['Error']['Code'] == 'InvalidRequestException':
print("The request was invalid due to:", e)
elif e.response['Error']['Code'] == 'InvalidParameterException':
print("The request had invalid params:", e)
elif e.response['Error']['Code'] == 'DecryptionFailure':
print("The requested secret can't be decrypted using the provided KMS key:", e)
elif e.response['Error']['Code'] == 'InternalServiceError':
print("An error occurred on service side:", e)
推荐阅读
- excel - 选择一列多个csv文件,并以可识别的顺序合并到一个文件中
- java - Socket.io 突然崩溃,说“java.lang.IllegalArgumentException:需要包含原因的代码”。
- regex - 正则表达式 - 使用“替换”使用捕获组删除内容
- reactjs - 开玩笑不使用我的模拟,而是用于通过 node_modules 导入的函数
- javascript - JS中频繁调用函数初始化数组的效率
- cmake - Catkin 无法找到 gmock - Ubuntu 16.04
- javascript - 用 Google Apps 脚本替换数组中的变音符号
- .htaccess - 尝试使用 .htaccess 添加查询参数
- c# - '查询值和目标字段的数量不同。'
- swagger - 将 Swagger-UI 与 Angular-8 应用程序集成