执行 lambda 函数时出现 Boto3 InvalidParameterException

Boto3 InvalidParameterException while executing the lambda function

我在 运行 lambda 函数时收到 Boto3 InvalidParameterException。 我正试图找出一种方法来处理这个异常。

我遇到了以下解决方案:

from boto.exception import BotoServerError

class InvalidParameterException(BotoServerError):
    pass

我正在使用 python3 并且了解到 boto 现在已被弃用并被 boto3 取代。 但是我在 boto3 中找不到等效的解决方案。

谁能帮我解决这个问题?

由于 boto 已弃用,所有 modeled 异常都可在客户端上使用。您也可以在 API 文档中查找相同的内容,基本上 boto3 的代码直接从 API 生成。 boto 的早期方法是硬编码的东西并为此编写代码。

如你所见here

例如

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)

AWS Secrets Manager Example From the docss