I am trying to download the .zip file of the layer.
I tried this command to get the location of the third party layer that I plan to use in my lambda function.
But the location URL is too long and I get 403 Forbidden error.
# aws lambda get-layer-version-by-arn --arn "arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p310-requests:9"
{
"Content": {
"Location": "https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/770693421928/Klayers-p310-requests-a-long-url-here",
"CodeSha256": "1vMDze/FCL0FyxN4ccNqUkK0JZM4i5wmMfZXYMY42LQ=",
"CodeSize": 888173
},
"LayerArn": "arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p310-requests",
"LayerVersionArn": "arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p310-requests:9",
"Description": "requests==2.31.0 | 147e396d4e434d6fb48e42bd7aa6f1453b3fd1b572be35b083ad06eb28f3e959",
"CreatedDate": "2024-03-01T02:06:11.454+0000",
"Version": 9,
"CompatibleRuntimes": [
"python3.10"
],
"LicenseInfo": "Apache 2.0",
"CompatibleArchitectures": [
"x86_64"
]
}
How to download the zip file of the layer provided by
someone else?
3
Answers
I assume that you are the owner or know the owner of the s3 bucket.
You can ask the owner for temporary access or to make the file public.
If they don’t know how, you can ask them to follow the instructions here.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html
They can either use the aws console or the cli.
They will be able to make a presigned key for you so that you can access the file.
If you are the owner you can also create a profile using IAM and give yourself access to the s3 bucket.
You can read this for more information.
https://repost.aws/knowledge-center/s3-console-access-certain-bucket
If your permissions are in order and the file name is simply too long, you could try using the AWS CLI with the aws s3 cp command to directly download the layer from the S3 bucket where Lambda layers are stored. Here’s how you can do it:
In your case, the URL provided is: https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/770693421928/Klayers-p310-requests-a-long-url-here
So, the bucket name would be
prod-04-2014-layers
and the key would besnapshots/770693421928/Klayers-p310-requests-a-long-url-here
.aws s3 cp s3://prod-04-2014-layers/snapshots/770693421928/Klayers-p310-requests-a-long-url-here layer.zip
Again, make sure you have the AWS CLI installed and configured with the necessary permissions to access the S3 bucket.
Get the location url (it should be pre-signed s3 url)
And paste in console with:
curl -o <location>
I understand that you want to download a Lambda layer in ZIP format that has been shared by someone else. To do this, you can use the
get-object
command in AWS CLI along with theLocation
URL that you get from theget-layer-version-by-arn
command.However, since you mentioned that you are facing a "403 Forbidden" error while trying to download the layer directly using the URL provided, in my experience that usually means that the layer is not publicly accessible. In this case, you need to use pre-signed URLs to download the layer.
To download the layer ZIP file using a pre-signed URL:
get-object
command with the--generate-presigned-url
option:Replace
prod-04-2014-layers
with the bucket name andsnapshots/770693421928/Klayers-p310-requests-a-long-url-here
with the object key (which is the part afterLocation
in theget-layer-version-by-arn
output).The
--expires-in
option specifies the duration (in seconds) for which the pre-signed URL is valid. Adjust it as needed.curl
orwget
to download the layer ZIP file:or
Once you execute the command, the layer ZIP file will be downloaded and saved as
layer.zip
in your current directory.Once the download is complete, you can use the file in your Lambda function by specifying its local file path when creating or updating the function.