- Newest
- Most votes
- Most comments
The error you're encountering suggests that the '@aws-crypto/client-node' package is not available by default in the AWS Lambda Node.js v20 runtime environment. This package is not included as part of the standard Lambda runtime, so you'll need to include it with your function code.
To resolve this issue, you have a few options:
- Include the package in your function's deployment package:
- Install the package locally in your project using npm or yarn.
- Make sure to include the node_modules directory when you zip and upload your function code.
- Use a Lambda Layer:
- Create a Lambda Layer that includes the '@aws-crypto/client-node' package.
- Attach this layer to your Lambda function.
- Use esbuild:
- If you're using AWS SAM (Serverless Application Model), you can use esbuild to bundle your dependencies.
- Add a Metadata object to your AWS::Serverless::Function resource and set BuildMethod to esbuild.
- This will automatically bundle your dependencies, including '@aws-crypto/client-node', with your function code.
Using a Lambda Layer or esbuild can help keep your deployment package size smaller and make dependency management easier, especially if you're using this package across multiple functions.
Remember to properly configure your function's execution role to have the necessary permissions, especially if you're using KMS (Key Management Service) related functionality, as indicated by your import statement.
Whichever method you choose, make sure to include the '@aws-crypto/client-node' package with your function deployment to resolve the "Cannot find package" error.
Sources
Building Node.js Lambda functions with esbuild in AWS SAM - AWS Serverless Application Model
answered 2 years ago
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 5 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 8 months ago
