Downloading Lambda layer versions using the AWS CLI

dereklawless

derek lawless

Posted on June 16, 2022

Downloading Lambda layer versions using the AWS CLI

The packaged .zip for a Lambda layer can be downloaded using the AWS console (appropriate IAM permissions notwithstanding) - as long as you have access to the host AWS account of course.

If the Lambda layer originates in a different AWS account you don't have console access to, you will need to use the AWS CLI.

Why would you want or need to do this though?

  1. As with any third party dependency it makes sense to examine it rather than simply trusting it to be benign in nature
  2. You want to override the layer's behaviour in a specific way (i.e. by merging a later layer) and need to examine its implementation

Fortunately, the aws lambda CLI provides two useful options - one for downloading a layer version by name, the other by its ARN.

Downloading a Lambda layer version by name

To download version 99 of a Lambda layer called acme-corp-lambda-layer using its name, use the get-layer-version option:

URL=$(aws lambda get-layer-version --layer-name ars:aws:lambda:$AWS_REGION:$AWS_ACME_CORP_ACCOUNT:layer:acme-corp-lambda-layer --version-number:99 --query Content.Location --output text)

curl $URL -o acme-corp-lambda-layer.zip
Enter fullscreen mode Exit fullscreen mode

Downloading a Lambda layer version by ARN

If you want to download version 99 of of the layer using its ARN instead, use get-layer-version-by-arn:

URL=$(aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:$AWS_ACME_CORP_ACCOUNT:layer:my-lambda-layer:99 --query Content.Location --output text)

curl $URL -o acme-corp-lambda-layer.zip
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
dereklawless
derek lawless

Posted on June 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related