小编Vij*_*a M的帖子

调用 GetSecretValue 操作时发生错误 (UnrecognizedClientException):请求中包含的安全令牌无效

请检查下面的屏幕截图,它有问题。AWS 凭证配置正确,当我们在 boto3 中单独使用时它工作正常,但在 SAM lambda 函数中触发它出现此错误。在此输入图像描述

尝试了所有解决方案,例如检查“aws configure”和取消设置AWS_SECURITY_TOKEN以及其他来源中提到的其他解决方案也尝试过但不起作用。

并在代码中尝试做

session = boto3.session.Session()
secretsmanager = session.client('secretsmanager')

try:
        get_secret_value_response = secretsmanager.get_secret_value(
            SecretId=secret_name
        )
        secret = json.loads(get_secret_value_response['SecretString'])
    except ClientError as e:
        print(e)
        # print(sys.exc_info(),traceback.print_exc(file=sys.stdout))
    except Exception as e:
        print(sys.exc_info(),traceback.print_exc(file=sys.stdout))
        print(e)
Run Code Online (Sandbox Code Playgroud)

python boto3 aws-sam

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

aws-sam ×1

boto3 ×1

python ×1