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?
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'.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With