Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up a lambda function in AWS to install certain packages and dependencies

Tags:

aws-lambda

I know there are deployment packages but what are these? Can they contain bash scripts that do apt-get install?

Is there any way to build a lambda function that uses a particular AMI

like image 673
n8CodeGuru Avatar asked Aug 29 '16 16:08

n8CodeGuru


2 Answers

You can run shell commands from inside your code(so technically you could run shell scripts) but you are charged for the time it takes your Lambda to execute - so installing a bunch of dependencies every time the Lambda starts up would be considered an anti-pattern.

You need to bundle all the packages and dependencies with your Lambda. This is done by uploading a zip file that contains the lambda function and all the dependencies.

You can see the official docs for the various supported languages here:

http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html

http://docs.aws.amazon.com/lambda/latest/dg/lambda-java-how-to-create-deployment-package.html

http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

like image 139
Ryan Avatar answered Oct 05 '22 06:10

Ryan


I think your are looking for something like lambda-uploader. You can list out the python packages required by your lambda. If you come across a package that requires a couple of library files to run, you can include them as well. Like for example, the mysql-python package requires libmysqlclient.so and _mysql.so files to run properly.

It generates the .zip file for you and deletes it once it has been uploaded. This way, you can avoid manual packaging steps and make deployment a breeze.

like image 23
Abhinav Avatar answered Oct 05 '22 06:10

Abhinav