Amazon Web Services (AWS) - Download Lambda Layer

by
Jeremy Canfield |
Updated: September 30 2024
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
The aws lambda list-layers command can be used to list the Lambda Layers you have created. Something like this should be returned.
~]# aws lambda list-layers
{
"Layers": [
{
"LayerName": "my_layer",
"LayerArn": "arn:aws:lambda:us-east-1:123456789012:layer:my_layer",
"LatestMatchingVersion": {
"LayerVersionArn": "arn:aws:lambda:us-east-1:123456789012:layer:my_layer:1",
"Version": 1,
"Description": "my super cool layer",
"CreatedDate": "2023-11-17T02:56:35.074+0000",
"CompatibleRuntimes": [
"python3.12"
]
}
}
]
}
The aws lambda get-layer-version command can be used to return a specific version of a specific Lambda Layer.
~]$ aws lambda get-layer-version --layer-name my_layer --version-number 1
{
"Content": {
"Location": "https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/123456789012/my_layer-4cfbc2f2-7b1c-434e-916b-bfd7d9cb7fd6?versionId=xyz987&X-Amz-Security-Token=abc123&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240930T104101Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ABC123us-east-1%2Fs3%2Faws4_request&X-Amz-Signature=7b899c7c2690b5c378bbbff5131b1cc23ac5141c4917307b380fdc04fbbdf404",
"CodeSha256": "iLPGwhO4vbD/BqU8DMLx3pl8tqnZUggsaKod2pPZDoY=",
"CodeSize": 1009
},
"LayerArn": "arn:aws:lambda:us-east-1:123456789012:layer:my_layer",
"LayerVersionArn": "arn:aws:lambda:us-east-1:123456789012:layer:my_layer:1",
"Description": "my super cool layer",
"CreatedDate": "2024-03-23T01:10:46.836+0000",
"Version": 3,
"CompatibleRuntimes": [
"python3.12"
]
}
To download the layer, you are going to want only the value of the Content -> Location key, as text.
aws lambda get-layer-version --layer-name my_layer --version-number 1 --query Content.Location --output text
Let's store the value of the Content.Location key in a variable named URL.
URL=$(aws lambda get-layer-version --layer-name my_layer --version-number 1 --query Content.Location --output text)
Then curl can be used to download the Lambda Layer as a .zip file.
curl $URL --output my_layer.zip
You can then unzip the .zip file.
unzip my_layer.zip -d /tmp
Did you find this article helpful?
If so, consider buying me a coffee over at