Skip to content

Commit 435cc5b

Browse files
authored
adds layers page (#7895)
* adds layers page
1 parent 5d1584c commit 435cc5b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ export const directory = {
382382
{
383383
path: 'src/pages/[platform]/build-a-backend/functions/streaming-logs/index.mdx'
384384
},
385+
{
386+
path: 'src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx'
387+
},
385388
{
386389
path: 'src/pages/[platform]/build-a-backend/functions/grant-access-to-other-resources/index.mdx'
387390
},
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Lambda Layers',
5+
description:
6+
'Learn how to add layers to your function',
7+
platforms: [
8+
'android',
9+
'angular',
10+
'flutter',
11+
'javascript',
12+
'nextjs',
13+
'react',
14+
'react-native',
15+
'swift',
16+
'vue'
17+
]
18+
};
19+
20+
export function getStaticPaths() {
21+
return getCustomStaticPath(meta.platforms);
22+
}
23+
24+
export function getStaticProps() {
25+
return {
26+
props: {
27+
meta
28+
}
29+
};
30+
}
31+
32+
Amplify offers the ability to add layers to your Functions which contain your library dependencies. To get started, specify the `layers` property in `defineFunction`:
33+
34+
```ts title="amplify/functions/my-function/resource.ts"
35+
import { defineFunction } from "@aws-amplify/backend";
36+
37+
export const myFunction = defineFunction({
38+
name: "my-function",
39+
layers: {
40+
"@aws-lambda-powertools/logger":
41+
"arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:12",
42+
},
43+
});
44+
```
45+
46+
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.
47+
48+
Then use the locally installed module in the function handler:
49+
```ts title="amplify/functions/my-function/handler.ts"
50+
import { Logger } from "@aws-lambda-powertools/logger";
51+
import type { Handler } from "aws-lambda";
52+
53+
const logger = new Logger({ serviceName: "serverlessAirline" });
54+
55+
export const handler: Handler = async (event, context) => {
56+
logger.info("Hello World");
57+
};
58+
```
59+
60+
For further information on creating and managing your layers refer to [AWS documentation for Lambda layers](https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html)
61+

0 commit comments

Comments
 (0)