Python - creating aws lambda deployment package

五迷三道 提交于 2021-01-27 10:42:04

问题


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?


回答1:


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()}
})

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'.




回答2:


Actually boto3 documentation is out of date, you should pass the bytes directly:

https://github.com/boto/boto3/issues/201

As to the zip file this should point you in the right direction:

  • http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
  • http://www.devshed.com/c/a/Python/Python-UnZipped/
  • https://docs.python.org/3/library/functions.html#bytearray


来源:https://stackoverflow.com/questions/34022161/python-creating-aws-lambda-deployment-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!