Skip to content

lambdas bundle in Amplify Gen 2

0

Hi, In Amplify Gen 2 (fullstack app), there are lambdas in the backend (amplify folder). I see that there are few package.json files: in root folder, in the amplify folder and optionally in the function folder.

I want to know which libraries (package.json) are installed for a lambda function, and which libraries (package.json) are installed for the client bundle?

For example: If I need package "uuid" only in a lambda function - where should I install this package? If I need package "pdf-parse" only in the client - where should I install this package?

Thanks

asked 10 months ago356 views
2 Answers
0

The function defined in Amplify Gen2 is implemented by CDK's NodejsFunction. The CDK project is treated as mono repo, the dependencies are managed in root project, refer to its project architecture for details.

AWS
answered 10 months ago
-2

In Amplify Gen 2 fullstack applications, the package management for Lambda functions and client-side code is separated to ensure proper bundling and deployment.

For Lambda functions: If you need a package like "uuid" only in a Lambda function, you should install it in the specific function's folder within the Amplify backend. Each Lambda function typically has its own package.json file. Navigate to the function's directory (usually found in amplify/backend/function/[function-name]) and install the package there using npm or yarn. This ensures that the package is bundled with the Lambda function when it's deployed.

For client-side code: If you need a package like "pdf-parse" only for the client-side of your application, you should install it in the root directory of your project. The package.json file in the root folder is used for managing dependencies for the client-side bundle. Install client-side packages here using npm or yarn.

The package.json file in the Amplify folder is generally used for Amplify-specific configurations and dependencies related to the Amplify CLI and build process. You typically don't need to manually modify or install packages in this file.

To summarize:

  • For Lambda-specific packages: Install in the individual function's folder (amplify/backend/function/[function-name])
  • For client-side packages: Install in the root directory of your project
  • The package.json in the Amplify folder is managed by Amplify CLI and shouldn't require manual modifications for your application's dependencies

This separation ensures that your Lambda functions only include the necessary dependencies, keeping the deployment package size optimized, while your client-side code has access to all the required libraries for the frontend application.
Sources
AWS Amplify Features | Front-End Web & Mobile | Amazon Web Services

answered 10 months ago
  • That's not true. In my lambda function, I tried to use library which is installed in the root package.json (client's package.json), and it worked

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.