San*_*anD 8 python amazon-web-services python-3.x aws-lambda python-3.6
我需要我的 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)
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误
No module named 'requests_aws4auth'
Run Code Online (Sandbox Code Playgroud)
任何使用 aws 凭据创建身份验证的解决方案或替代方法也将受到欢迎。
将源代码和依赖项打包到 zip 文件中,将其上传到 S3,然后使用 AWS::Lambda::Function 资源下的 S3Bucket 和 S3Keys 属性。
例如在 Linux 上:
mkdir project-dir
cp myhandler.py project-dir
pip install module-name -t /path/to/project-dir
# zip the contents of project-dir , this is your deployment package
cd project-dir
zip -r deployme.zip .
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12000 次 |
| 最近记录: |