AWS CodeCatalyst Rest API project blueprint: How to add external libraries (Python + Lambda)

0

Hello team,

I am using AWS CodeCatalyst and have created a Rest API project using an available blueprint. I am using Python language for my project.

It is working with the initial setup. I am able to deploy code and test. However, I need to add external libraries for my use case.

Does CodeCatalyst provide any simple way to add external Python libraries to my lambda function? Or do I need to explicitly create a new Lambda layer for adding external libraries?

I've tried adding the libraries to requirements.txt and running pip install but lambda is throwing Unable to import module 'lambda_function_name', No module named 'external_library'

Thank you.

질문됨 일 년 전2547회 조회
1개 답변
4
수락된 답변

To add external Python libraries to your AWS CodeCatalyst Rest API project, you can create a new Lambda layer and upload the required libraries to it. Here are the steps

  • Create a directory on your local machine for the layer, and add a subdirectory named "python".
  • Inside the "python" directory, create a "site-packages" directory.
  • Use pip to install the required external libraries into the "site-packages" directory. For example, you can run the following command to install the "requests" library: pip install requests -t python/site-packages.
  • Zip the contents of the "python" directory. You can use the following command to zip the directory: cd python && zip -r ../layer.zip *.
  • Upload the resulting "layer.zip" file to AWS Lambda Layers. You can do this through the AWS Management Console or using the AWS CLI.
  • Once the layer is uploaded, you can add it to your Lambda function in AWS CodeCatalyst by referencing its ARN in the "Layers" section of the Lambda function configuration.
profile picture
전문가
답변함 일 년 전
profile picture
전문가
검토됨 한 달 전
  • Thank you for the detailed instructions. I had to follow a slightly different directory structure to make it work.

    Created a directory named 'python' and installed the library directly under the 'python' directory (didn't require the site-packages subdirectory).

    zip (python/library files)

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠