I want to create an AWS Lambda deployment package that contains binary shared library dependencies. How can I use the Amazon Linux AMI packages without recompiling the package?
A Lambda deployment package is a .zip file that contains your code and any dependencies. The Lambda execution environment is based on a specific Amazon Linux AMI and kernel version. Any native binaries that are used in a Lambda deployment package must be compiled in this environment, and only 64-bit binaries are supported.
To use the Amazon Linux AMI native binary packages, you can extract the 64-bit libraries and then include them in your Lambda deployment package. (Another option, that is not covered in this article, is to download the source code to the shared library and then recompile the package.)
Launch an Amazon EC2 instance from the Amazon Linux AMI
1. Open Lambda Execution Environment and Available Libraries and find the AMI name that starts with "amzn-ami-hvm."
2. Choose the AMI name link to open the Amazon Elastic Compute Cloud (Amazon EC2) console to a search result for the AMI.
3. Choose Launch to open the Launch Instance wizard.
4. Choose Review and Launch to accept the default instance launch details in the wizard, and then choose Launch.
Extract libraries from the instance
1. Connect to the instance, and then run the following command to install tools to extract the packages:
sudo yum install -y yum-utils rpmdevtools
2. If you don't know which libraries and dependencies your code requires, use yum to find them.
For example, for FreeTDS libraries for Microsoft SQL Server and Sybase databases, run the following command:
sudo yum install freetds
Note: In this example, you'll also get prompts to install gnutls, libtool-ltdl, and unixODBC for dependencies.
3. To download and extract the libraries and the dependencies, run the following command:
cd /tmp yumdownloader unixODBC.x86_64 freetds.x86_64 libtool-ltdl.x86_64 gnutls.x86_64 rpmdev-extract *rpm
4. To copy the libraries into a directory for the Lambda deployment package, run the following commands:
sudo mkdir -p /var/task sudo chown ec2-user:ec2-user /var/task cd /var/task /bin/cp /tmp/*/usr/lib64/* /var/task
Create a deployment package
Do one of the following:
- Copy your code and other resources into the same directory, perform any configuration specific to your code and runtime environment, and then test.
- Create a .zip file deployment package by running the following command:
cd /var/task zip -r9 /tmp/MyCodeWithLibraries.zip *
Deploy the .zip file deployment package, and then test.
For more information about creating a deployment package, see Sample Function Code and Create a Lambda Function Using Environment Variables.