aws-powertools / powertools-lambda-typescript

Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/typescript/latest/
MIT No Attribution
1.57k stars 138 forks source link

Maintenance: update layer art in CDK example #1793

Closed apmclean closed 11 months ago

apmclean commented 11 months ago

Expected Behaviour

CDK Example found at examples/cdk/README.md functions as described

Current Behaviour

Deployment succeeds, however invocation of the API Gateway URL produces an Internal Error.

Looking at the Lambda functions logs it produces:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@aws-lambda-powertools/parameters/ssm'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '@aws-lambda-powertools/parameters/ssm'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
        "    at async start (file:///var/runtime/index.mjs:1282:23)",
        "    at async file:///var/runtime/index.mjs:1288:1"
    ]
}

Code snippet

Follow instructions: examples/cdk/README.md

Steps to Reproduce

Follow instructions: examples/cdk/README.md

Possible Solution

Looking at examples/cdk/src/example-stack.ts - Runtime of NodeJS 20 is specified as a default:

const commonProps: Partial<NodejsFunctionProps> = {
  runtime: Runtime.NODEJS_20_X,
  tracing: Tracing.ACTIVE,
...

However version :18 of the Lambda Layer is specified:

    commonProps.layers?.push(
      LayerVersion.fromLayerVersionArn(
        this,
        'powertools-layer',
        `arn:aws:lambda:${
          Stack.of(this).region
        }:094274105915:layer:AWSLambdaPowertoolsTypeScript:18`
      )
    );

Viewing the Layer configuration in the Lambda console shows that NodeJS 20 is not supported. Support Runtimes for that layer version are:

image

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

Lambda Layers

Execution logs

No response

boring-cyborg[bot] commented 11 months ago

Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

am29d commented 11 months ago

Hey @apmclean , thanks for opening the issue and the detailed description, greatly appreciated!

It seems we forgot to update the layer version in our CDK example. Version 18 does not include the ssm parameter package. In the meantime, if you set the ARN of layer to version 24, this will resolve the issue.

Also, feel free to submit a PR, if you like, happy to merge it 👍

daschaa commented 11 months ago

I would like to take this issue

github-actions[bot] commented 11 months ago

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.