- Newest
- Most votes
- Most comments
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.
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
Relevant content
- asked 3 months ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 4 years 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