Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda and zip upload from S3

This feature is not clear to me about the benefits (I didn't find any good documentation):

  1. Is it just faster in the case you reuse the same zip for many lambda functions because you upload only 1 time and you just give the S3 link URL to each lambda function?
  2. If you use an S3 link, will all your lambda functions be updated with the latest code automatically when you re-upload the zip file, meaning is the zip file on S3 a "reference" to use at each call to a lambda function?

Thank you.

EDIT:
I have been asked "Why do you want the same code for multiple Lambda functions anyway?" Because I use AWS Lambda with AWS API Gateway so I have 1 project with all my handlers which are actual "endpoints" for my RESTful API.

EDIT #2: I confirm that uploading a modified version of the zip file on S3 doesn't change the existing lambda functions result.

If an AWS guy reads this message, that would be great to have a kind of batch update feature that updates a set of selected lambda functions with 1 zip file on S3 in 1 click (or even an "automatic update" feature that detects when the file has been updated ;-))
Let's say you have 50 handlers in 1 project, then you modify something global impacting all of them, currently you have to go through all your lambda functions and update the zip file manually...

like image 682
Maxime Laval Avatar asked Feb 03 '16 22:02

Maxime Laval


2 Answers

The code is imported from the zip to Lambda. It is exactly the same as uploading the zip file through the Lambda console or API. However, if your Lambda function is big (they say >10MB), they recommend uploading to S3 and then using the S3 import functionality because that is more stable than directly uploading from the Lambda page. Other than that, there is no benefit.

So for question 1: no. Why do you want the same code for multiple Lambda functions anyway?

Question 2: If you overwrite the zip you will not update the Lambda function code.

like image 82
Luc Hendriks Avatar answered Sep 28 '22 07:09

Luc Hendriks


To add to other people's use cases, having the ability to update a Lambda function from S3 is extremely useful within an automated deployment / CI process.

The instructions under New Deployment Options for AWS Lambda include a simple Lambda function that can be used to copy a ZIP file from S3 to Lambda itself, as well as instructions for triggering its execution when a new file is uploaded.

As an example of how easy this can make development and deployment, my current workflow is:

  1. I update my Node lambda application on my local machine, and git commit it to a remote repository.

  2. A Jenkins instance picks up the commit, pulls down the appropriate files, adds them into a ZIP file and uploads this to an S3 bucket.

  3. The LambdaDeployment function then automatically deploys this new version for me, without me needing to even leave my development environment.

like image 30
Adrian Wragg Avatar answered Sep 28 '22 07:09

Adrian Wragg