Sharing Lambda Layers - Amazon Serverless Application Repository
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Sharing Lambda Layers

If you've implemented functionality in a Lambda layer, you might want to share your layer without hosting a global instance of it. Sharing layers in this manner enables others to deploy an instance of your layer to their own account. This prevents client applications from depending on a global instance of your layer. The Amazon Serverless Application Repository enables you to share Lambda layers in this manner easily.

For more information about Lambda layers, see Amazon Lambda Layers in the Amazon Lambda Developer Guide.

How It Works

The following are the steps for sharing your layer using the Amazon Serverless Application Repository. This allows a copy of your layer to be created in the user's Amazon account.

  1. Define a serverless application with an Amazon SAM template that includes your layer as a resource— that is, either an AWS::Serverless::LayerVersion or an AWS::Lambda::LayerVersion resource.

  2. Publish your application to the Amazon Serverless Application Repository, and share it (either publicly or privately).

  3. A customer deploys your application, which creates a copy of your layer in their own Amazon account. The customer can now reference the Amazon Resource Name (ARN) of the layer in their Amazon account in their client application.

Example

The following is an example Amazon SAM template for an application that contains the Lambda layer that you want to share:

Resources: SharedLayer: Type: AWS::Serverless::LayerVersion Properties: LayerName: shared-layer ContentUri: source/layer-code/ CompatibleRuntimes: - python3.7 Outputs: LayerArn: Value: !Ref SharedLayer

When a customer deploys your application from the Amazon Serverless Application Repository, a layer is created in their Amazon account. The ARN of the layer looks something like the following:

arn:aws:lambda:us-east-1:012345678901:layer:shared-layer:1

The customer can now reference this ARN in their own client application, like in this example:

Resources: MyFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.7 CodeUrl: source/app-code/ Layers: - arn:aws:lambda:us-east-1:012345678901:layer:shared-layer:1