How can I use AWS Cloud9 to deploy Lambda functions with external libraries?

Last updated: 2020-01-30

I want to use additional external libraries for AWS Lambda functions developed using AWS Cloud9. How can I import modules from those libraries so that they're included in my Lambda functions upon deployment?


Before you begin, be sure to:

Import the modules

Note: These instructions use Python as an example. The steps are similar for Node.js.

1.    Open the AWS Cloud9 console.

2.    Open your AWS Cloud9 environment.

3.    In the left navigation pane, choose the Environment button to open the Environment window.

4.    The parent folder of your Lambda function is listed with the same name as your function. Open the context (right-click) menu for the parent folder of your function.

5.    Choose Open Terminal Here to start a terminal session.

6.    In the terminal, run this command to install a module:

Note: Replace ModuleName with the name of a module that you want to import.

python -m pip install --target=./ ModuleName

7.    Repeat step 6 for each module that you want to import.

8.    After you install the modules, they populate the parent folder of your function.

Deploy your function with the modules

After you develop your Lambda function in your AWS Cloud9 environment, deploy the function with the additional modules.

1.    Open the Lambda section of the AWS Resources window.

2.    Under Local Functions, open the context (right-click) menu for your function.

3.    Choose Deploy.

After deploying your function, you can run your code using the additional modules that you imported.