amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

adds layers to function

Open ykethan opened this issue 1 year ago • 1 comments

Problem

Issue number, if available: RFC: https://github.com/aws-amplify/amplify-backend/issues/1549

Changes

adds ability to reference Lambda layers and attach to a function. Can attach up to 5 layers on a function. Auto sets the layer keys as external modules on the function.

example:

resource.ts

import { defineFunction } from "@aws-amplify/backend";

export const sayHello = defineFunction({
  name: "say-hello1",
  entry: "./handler.ts",
  layers: {
   "@aws-lambda-powertools/logger":
      "arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:11",
  },
});

handler.ts. keep using your dependancy without having to use /opt as the NODE_PATH would point to /opt: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime

import { Logger } from "@aws-lambda-powertools/logger";

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

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

Validation

Checklist

  • [ ] If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • [ ] If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • [ ] If this PR requires a docs update, I have linked to that docs PR above.
  • [ ] If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

ykethan avatar Aug 08 '24 14:08 ykethan

🦋 Changeset detected

Latest commit: 9f80bfed903d633035f06875e5e40bf683b5e039

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-amplify/backend-function Minor
@aws-amplify/backend Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Aug 08 '24 14:08 changeset-bot[bot]