Sharing a Lambda layer across multiple AWS accounts

To share a layer between accounts or even publish it publicly, you need to use the AWS CLI or the API, as this is not supported in the console yet. We add permission statements using the AddLayerVersionPermission API action, which is similar to the way we do it with Lambda functions.

The following command is what we use to share a Lambda layer with another account:

aws lambda add-layer-version-permission    --layer-name MessageVendorLayer    --version-number 1    --statement-id sharingWithOneAccount    --principal 123456789012    --action lambda:GetLayerVersion

What the preceding command will achieve is sharing version 1 of our layer to the AWS account with ID 123456789012. You could replace this principal ...

Get Learn AWS Serverless Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.