AWS Lambda

Export Layer

1. Get the Layer ARN

Ensure you have the full ARN of the Lambda Layer. It typically looks like:

arn:aws:lambda:<region>:<account-id>:layer:<layer-name>:<version>

For example:

arn:aws:lambda:us-east-1:123456789012:layer:my-nodejs-layer:3

2. Download the Layer Using AWS CLI

You can use the AWS CLI to download the Lambda Layer as a ZIP file:

aws lambda get-layer-version-by-arn --arn <layer-arn> --query 'Content.Location' --output text

This command returns a pre-signed URL to download the layer. Use curl or wget to download it:

curl -o nodejs-layer.zip "<download-url>"

3. Extract the Layer

Unzip the downloaded file:

unzip nodejs-layer.zip -d nodejs-layer

4. Inspect the Directory Structure

For Node.js 18, the Lambda Layer typically follows this structure:

nodejs-layer/
└── nodejs/
    ├── node_modules/
    └── package.json

If the layer contains native binaries or other resources, they might be located in additional directories within the ZIP file.

Debugging

Cannot find package 'uuid' imported from /var/task/index.mjs

If your Lambda Layer contains @types/uuid but not the actual uuid package, it means you only have the TypeScript type definitions installed, not the actual library. The @types/uuid package provides type information for TypeScript, but it does not include the actual code for uuid. This is why your Lambda function is throwing an error when it tries to import it.

How to Fix It

You need to make sure that both uuid and @types/uuid are installed in your Lambda Layer.

1. Install uuid Library

If you haven't already, install the uuid package along with its type definitions:

npm install uuid @types/uuid
2. Verify the node_modules Structure

Ensure that your node_modules directory has both the uuid and @types/uuid folders:

nodejs/
├── node_modules/
│   ├── uuid/
│   └── @types/
│       └── uuid/
└── package.json