Python-创建AWS Lambda部署包 [英] Python - creating aws lambda deployment package
问题描述
我想使用Fabric任务为AWS Lambda的更新代码编写脚本.Boto3 API需要一个以base-64编码的zip文件的字节数组.
I want to script updating code for my AWS Lambda using a Fabric task. Boto3 api expects a byte array of base-64 encoded zip file.
假设我将源代码文件作为输入,创建它的最简单方法是什么?
What would be the simplest way to create it assuming I have the source code files as the input?
推荐答案
使用当前的boto3,请勿将其解压缩,也不要对其进行base64编码.您可以像这样打开并阅读:
With the current boto3, don't unzip it, don't base64 encode it. You can do it with an open and a read like this:
import boto3
c = boto3.client('lambda')
c.create_function({
'FunctionName': 'your_function',
'Handler': 'your_handler',
'Runtime': 'python3.6',
'Code': {'ZipFile': open('./deploy.zip', 'rb').read()}
})
我使用上面的zip文件快速入门.您还可以将deploy.zip上传到S3存储桶,并将存储桶+键作为字符串传递给代码"字典中的字符串,如"S3Bucket"和"S3Key".
I use the zip file above for getting started quickly. You can also upload the deploy.zip to a S3 bucket and pass the bucket + key as strings in the 'Code' dict as 'S3Bucket' and 'S3Key'.
这篇关于Python-创建AWS Lambda部署包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!