From ba10f667e3fd6479e31a4e84203b9df865449178 Mon Sep 17 00:00:00 2001 From: ykethan Date: Thu, 15 Aug 2024 15:11:40 -0400 Subject: [PATCH 1/4] adds layers page --- src/directory/directory.mjs | 3 + .../functions/add-lambda-layers/index.mdx | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index d8bcb643a59..46318a737f5 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -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' }, diff --git a/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx new file mode 100644 index 00000000000..8401aef0979 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx @@ -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 => { + 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) + From 1497734376fcb4791e5ff17d3de9e4c0ad4a9960 Mon Sep 17 00:00:00 2001 From: ykethan Date: Wed, 9 Oct 2024 16:16:34 -0400 Subject: [PATCH 2/4] update info --- next-env.d.ts | 2 +- .../build-a-backend/functions/add-lambda-layers/index.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03dc6c..a4a7b3f5cfa 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx index 8401aef0979..bad18494e18 100644 --- a/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx @@ -43,7 +43,7 @@ export const myFunction = defineFunction({ }); ``` -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. +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: ```ts title="amplify/functions/my-function/handler.ts" From 1f73431a5adcd765d3979f2542964aa19d9bd6c5 Mon Sep 17 00:00:00 2001 From: ykethan Date: Wed, 9 Oct 2024 17:06:00 -0400 Subject: [PATCH 3/4] minor nits --- .../build-a-backend/functions/add-lambda-layers/index.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx index bad18494e18..692dd796868 100644 --- a/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/add-lambda-layers/index.mdx @@ -45,13 +45,14 @@ export const myFunction = defineFunction({ 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: +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"; +import type { Handler } from "aws-lambda"; const logger = new Logger({ serviceName: "serverlessAirline" }); -export const handler = async (): Promise => { +export const handler: Handler = async (event, context) => { logger.info("Hello World"); }; ``` From e1827a6122af1f8e3088c8ec6189b2a049fca3a4 Mon Sep 17 00:00:00 2001 From: ykethan Date: Wed, 9 Oct 2024 22:53:37 -0400 Subject: [PATCH 4/4] rm changes --- next-env.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next-env.d.ts b/next-env.d.ts index a4a7b3f5cfa..4f11a03dc6c 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/basic-features/typescript for more information.