Bootstrap FreeKB - Amazon Web Services (AWS) - Publish a Lambda Layer using the AWS CLI
Amazon Web Services (AWS) - Publish a Lambda Layer using the AWS CLI

Updated:   |  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 publish-layer-version command can be used to publish a Lambda Layer using a zip file, so before you can publish a Lambda Layer, you'll need a zip file. For example, on a Linux system, you could use wget to download the paramiko tar.

wget https://files.pythonhosted.org/packages/44/03/158ae1dcb950bd96f04038502238159e116fafb27addf5df1ba35068f2d6/paramiko-3.3.1.tar.gz

 

Use tar to extract the tar archive.

tar -zxpf paramiko-3.3.1.tar.gz --directory /tmp

 

You can now remove the tar file.

rm paramiko-3.3.1.tar.gz

 

Rename the extracted directory from /tmp/paramiko-3.3.1/ to /tmp/python/. This is needed so that when the zip file is created, the base directory in the zip archive will be python and all of the files and directories that were extracted will be below the python directory. Refer to Packaging your layer content - AWS Lambda (amazon.com) for more details on why this is required.

mv /tmp/paramiko-3.3.1 /tmp/python

 

zip the extracted files.

cd /tmp/
zip --recurse-path /tmp/paramiko-3.3.1.zip python/

 

You can now remove the /tmp/python/ directory.

rm -rf /tmp/python

 

And then the aws lambda publish-layer-version command can be used to publish the Lambda Layer using the zip file.

aws lambda publish-layer-version --layer-name paramiko --zip-file fileb://paramiko.zip --compatible-runtimes python3.11  python3.12

 

Something like this should be returned.


    "Content": {
        "Location": "https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/123456789012/sendgrid_pip-11fb6dd0-4e7a-4d02-8eed-732f9d6302f0?versionId=vj.fYoJHKxn1vpW5AG5UwGceBTrEAVdr&X-Amz-Security-Token=IQoJ.....b3dda",
        "CodeSha256": "pGGkyZe/YwIqSyCPYInE9QlDe6TKEvoEPUot8nfUg/k=",
        "CodeSize": 393575
    },
    "LayerArn": "arn:aws:lambda:us-east-1:123456789012:layer:paramiko",
    "LayerVersionArn": "arn:aws:lambda:us-east-1:123456789012:layer:paramiko:1",
    "Description": "",
    "CreatedDate": "2023-12-11T11:14:41.172+0000",
    "Version": 1,
    "CompatibleRuntimes": [
        "python3.11"
    ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 90782d in the box below so that we can be sure you are a human.