我需要我的lambda调用API网关,并在我的云形成模板中将以下代码作为lambda的内联代码。
from requests_aws4auth import AWS4Auth
def handler(event,context):
client = boto3.client('sts')
responseAssumeRole = client.assume_role(
DurationSeconds=3600,
RoleArn='arn',// real arn of the api gateway invocation role
RoleSessionName='Bob',
)
credentials = responseAssumeRole['Credentials']
auth = AWS4Auth(aws_access_key=responseAssumeRole['Credentials']['AccessKeyId'],
aws_secret_access_key=responseAssumeRole['Credentials']['SecretAccessKey'],
aws_host='host.execute-api.us-east-1.amazonaws.com',
aws_region='us-east-1',
aws_service='execute-api')
headers= {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
response = requests.get('https://host.execute-api.us-east-1.amazonaws.com/test',
auth=auth, headers=headers)
这给了我以下错误
No module named 'requests_aws4auth'
也欢迎使用aws凭据创建身份验证的任何解决方案或替代方法。
也许您也可以使用上下文初始值设定项来解决此问题,如下面的答案所示:
Spring Environment backed by Typesafe Config
TL;博士
如果无法在自定义impl中处理
path
,则返回null
解释
最有可能的场景是,在任何默认实现之前,解析顺序将考虑我们的自定义实现。在我们的实现中使用的方法将与包含“:”和“[”的任何路径一起出错,因为在检查路径是否存在时出错
我只是包装
BadPath
异常以捕获任何问题,然后返回null表示不匹配相关问题 更多 >
编程相关推荐