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 this procedure, be sure that:

Import the modules

Note: This tutorial uses Python as an example; the steps are similar when using Node.js.

1. Open the AWS Cloud9 console.

2. Under your AWS Cloud9 environment, choose Open IDE.

3. From the navigation pane on the left, choose the Environment view.

4. The parent folder of your Lambda function is listed with the same name as your function. Right-click the parent folder of your function. 

5. Choose Open Terminal Here.

6. After the terminal view opens, run this command to install a module:

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

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

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

Deploy the Lambda function with the modules

After you develop your function in your AWS Cloud9 environment, follow these steps to deploy your function with the additional modules:

1. From the navigation pane on the right, choose the AWS Resources view.

2. Under Local Functions, right-click on your function.

3. Choose Deploy.

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

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-12-05