aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.7k stars 3.93k forks source link

aws_lambda_nodejs: NodeJSFunction fails with Runtime.NODEJS_22_X #32239

Open jusdino opened 15 hours ago

jusdino commented 15 hours ago

Describe the bug

It appears that aws-cdk-lib (2.169.0 at least) was updated to include Runtime.NODEJS_22_X before the corresponding SAM docker image that NodeJSFunction uses is available: https://gallery.ecr.aws/sam/build-nodejs22.x

So trying to build functions with the latest runtime fails to synth:

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/kdycg60fbl6m4doqe0nut343f
#0 building with "desktop-linux" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 1.40kB done
#1 DONE 0.0s

#2 [internal] load metadata for public.ecr.aws/sam/build-nodejs22.x:latest
#2 ERROR: public.ecr.aws/sam/build-nodejs22.x:latest: not found
------
 > [internal] load metadata for public.ecr.aws/sam/build-nodejs22.x:latest:
------
Dockerfile:4
--------------------
   2 |     # passed as build arg. The default allows to do `docker build .` when testing.
   3 |     ARG IMAGE=public.ecr.aws/sam/build-nodejs18.x
   4 | >>> FROM $IMAGE
   5 |     
   6 |     # Install yarn
--------------------
ERROR: failed to solve: public.ecr.aws/sam/build-nodejs22.x: failed to resolve source metadata for public.ecr.aws/sam/build-nodejs22.x:latest: public.ecr.aws/sam/build-nodejs22.x:latest: not found

Regression Issue

Last Known Working CDK Version

No response

Expected Behavior

The function should bundle successfully

Current Behavior

The function fails bundling when it attempts to pull down a container image that does not yet exist.

Reproduction Steps

Create a basic cdk app with a JS lambda folder like

├── app.py
├── cdk.json
│       └── index.js
└── local_folder
    ├── index.js
    ├── package-lock.json
    └── package.json
# app.py

import os

from aws_cdk import App, Stack
from aws_cdk.aws_lambda import Runtime
from aws_cdk.aws_lambda_nodejs import NodejsFunction

app = App()
stack = Stack(app, 'Broken')
NodejsFunction(
    stack,
    'BrokenFunction',
    runtime=Runtime.NODEJS_22_X,
    entry=os.path.join('local_folder', 'index.js'),
    deps_lock_file_path=os.path.join('local_folder', 'package-lock.json'),
    handler='handler',
)

Node 20_x builds, Node 22_x does not

Possible Solution

Ideally, ask the sam team to get an image out? (or maybe even coordinate timing of future runtime updates in CDK releases with SAM image availability?) Until then, a more helpful error message or something might help reduce thrash as developers do what I did:

Additional Information/Context

No response

CDK CLI Version

2.169.0

Framework Version

No response

Node.js Version

22.1.0

OS

MacOS

Language

Python

Language Version

3.12.3

Other information

No response

ashishdhingra commented 13 hours ago

Issue reproducible using below code:

import os
from aws_cdk import (
    # Duration,
    Stack,
    aws_ec2 as ec2,
    aws_lambda as awslambda,
    aws_lambda_nodejs as lambdanodejs
)
from constructs import Construct

class CdktestPythonStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        lambdanodejs.NodejsFunction(
            self,
            'BrokenFunction',
            runtime=awslambda.Runtime.NODEJS_22_X,
            entry=os.path.join('local_folder', 'index.js'),
            handler='index.handler',
            deps_lock_file_path=os.path.join('local_folder', 'package-lock.json'),
        )

Running cdk synth gives below error:

#0 building with "desktop-linux" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 1.36kB done
#1 DONE 0.0s

#2 [internal] load metadata for public.ecr.aws/sam/build-nodejs22.x:latest
#2 ERROR: public.ecr.aws/sam/build-nodejs22.x:latest: not found
------
 > [internal] load metadata for public.ecr.aws/sam/build-nodejs22.x:latest:
------
Dockerfile:4
--------------------
   2 |     # passed as build arg. The default allows to do `docker build .` when testing.
   3 |     ARG IMAGE=public.ecr.aws/sam/build-nodejs18.x
   4 | >>> FROM $IMAGE
   5 |     
   6 |     # Install yarn
--------------------
ERROR: failed to solve: public.ecr.aws/sam/build-nodejs22.x: failed to resolve source metadata for public.ecr.aws/sam/build-nodejs22.x:latest: public.ecr.aws/sam/build-nodejs22.x:latest: not found

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/plw3vyn4s1v06ommx868bqe5c
jsii.errors.JavaScriptError: 
  Error: docker exited with status 1
  --> Command: docker build -t cdk-0093a40e620649ff7aea9f457996457645f33db41a5d05fd2c7487ac204070de --platform "linux/amd64" --build-arg "IMAGE=public.ecr.aws/sam/build-nodejs22.x" --build-arg "ESBUILD_VERSION=0.21" 
...

Examining Image Tags at https://gallery.ecr.aws/sam/build-nodejs22.x, it appears that as of now, there is no image tagged as latest (as compared to https://gallery.ecr.aws/sam/build-nodejs20.x).

@jusdino This appears to be sync problem across different teams. Could you please open issue at https://github.com/aws/aws-sam-cli so that you get any updates as the issue is being worked upon?

Thanks, Ashish

moelasmar commented 12 hours ago

Thanks @jusdino for raising this issue. As you mentioned, the image creation is handled by sam-cli team, and they are currently working on it. It will be available soon. I will update the issue once the image is available.

moelasmar commented 10 hours ago

The image is available now. Please check if it fixes your issue.

jusdino commented 7 hours ago

Yep, issue fixed now that the Node 22_X images are available. Thanks!

Any chance there's a way to reduce turbulence between the teams for whenever Node 24 comes out?