Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds layers page #7895

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/directory/directory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ export const directory = {
{
path: 'src/pages/[platform]/build-a-backend/functions/streaming-logs/index.mdx'
},
{
path: 'src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx'
},
{
path: 'src/pages/[platform]/build-a-backend/functions/grant-access-to-other-resources/index.mdx'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';

export const meta = {
title: 'Lambda Layers',
description:
'Learn how to add layers to your function',
platforms: [
'android',
'angular',
'flutter',
'javascript',
'nextjs',
'react',
'react-native',
'swift',
'vue'
]
};

export function getStaticPaths() {
return getCustomStaticPath(meta.platforms);
}

export function getStaticProps() {
return {
props: {
meta
}
};
}

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

```ts title="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 key for the layer is a module name hosted on your existing layer and will be externalized ensuring the module is not bundled with your function. The value accepts an Arn that references to a version of your layer that exists in the same region as your function. You can add upto 5 layers in your function.

then use the locally installed module in the function handler:
```ts title="amplify/functions/my-function/handler.ts"
import { Logger } from "@aws-lambda-powertools/logger";

const logger = new Logger({ serviceName: "serverlessAirline" });

export const handler = async (): Promise<void> => {
logger.info("Hello World");
};
```

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)