Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Page updated Oct 10, 2024

Lambda Layers

Amplify offers the ability to add layers to your Functions which contain your library dependencies. To get started, specify the layers property in defineFunction:

amplify/functions/my-function/resource.ts
import { defineFunction } from "@aws-amplify/backend";
export const myFunction = defineFunction({
name: "my-function",
layers: {
"@aws-lambda-powertools/logger":
"arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:12",
},
});

The Lambda layer is represented by an object of key/value pairs where the key is the module name that is exported from your layer and the value is the ARN of the layer. The key (module name) is used to externalize the module dependency so it doesn't get bundled with your lambda function. A maximum of 5 layers can be attached to a function, and they must be in the same region as the function.

Then use the locally installed module in the function handler:

amplify/functions/my-function/handler.ts
import { Logger } from "@aws-lambda-powertools/logger";
import type { Handler } from "aws-lambda";
const logger = new Logger({ serviceName: "serverlessAirline" });
export const handler: Handler = async (event, context) => {
logger.info("Hello World");
};

For further information on creating and managing your layers refer to AWS documentation for Lambda layers