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.57k stars 3.88k forks source link

NodejsFunction: can't pull images due to failed to solve with frontend dockerfile.v0 #25396

Open ajohnston1219 opened 1 year ago

ajohnston1219 commented 1 year ago

Describe the bug

When building a NodejsFunction using the bundling.forceDockerBundling: true flag, the docker image cannot be pulled due to failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests latest]: 400 Bad Request.

Expected Behavior

The docker image is pulled and the lambda function is bundled properly

Current Behavior

cdk diff results in:

[+] Building 0.5s (3/3) FINISHED                                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                                              0.0s
 => => transferring dockerfile: 37B                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                   0.0s
 => ERROR [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest                                                                                                 0.4s
------
 > [internal] load metadata for public.ecr.aws/sam/build-nodejs16.x:latest:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests latest]: 400 Bad Request
/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/core/lib/bundling.js:4
stderr: ${proc.stderr?.toString().trim()}`):new Error(`${prog} exited with status ${proc.status}`);return proc}function isSeLinux(){if(process.platform!="linux")return!1;const prog="selinuxenabled",proc=child_process_1.spawnSync(prog,[],{stdio:["pipe",process.stderr,"inherit"]});return proc.error?!1:proc.status==0}
                                            ^
Error: docker exited with status 1
    at dockerExec (/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/core/lib/bundling.js:4:45)
    at Function.fromBuild (/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/core/lib/bundling.js:1:3494)
    at new Bundling (/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.js:1:1897)
    at Function.bundle (/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.js:1:2733)
    at new NodejsFunction (/Users/adam/projects/rome/common/temp/node_modules/.pnpm/aws-cdk-lib@2.43.1_constructs@10.2.9/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/function.js:1:1229)
    at new deviceManagementAPILambda (/Users/adam/projects/rome/services/device-management/lib/device-management-api-lambda.ts:60:23)
    at new DeviceManagementStack (/Users/adam/projects/rome/services/device-management/lib/device-management-stack.ts:69:23)
    at Object.<anonymous> (/Users/adam/projects/rome/services/device-management/bin/device-management.ts:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)

Subprocess exited with error 1

Reproduction Steps

create a lambda function like:

new NodejsFunction(this, 'some-function', {
  ...normalProps,
  runtime: Runtime.NODEJS_16_X,
  bundling: {
      forceDockerBundling: true,
  },
});

Then run cdk diff, or any other cdk command that bundles the function

Possible Solution

From what I can tell from an online search, this has something to do with the image type? I tried ARM_64 and X86_64, but both failed

Additional Information/Context

OS: Mac OS 13.3.1 (22E261) CDK Version: 2.43.1 (build c1ebb85) Docker version 20.10.24, build 297e128

CDK CLI Version

2.43.1

Framework Version

No response

Node.js Version

16.x

OS

Mac OS 13.3.1

Language

Typescript

Language Version

5.0.4

Other information

This was the first stack overflow post when I searched the error: https://stackoverflow.com/questions/68984133/error-failed-to-solve-with-frontend-dockerfile-v0-failed-to-create-llb-defini

pahud commented 1 year ago

Looks like the dockerfile is missing but I can't reproduce this in my environment.

Can you install the latest AWS CDK v2 and try again? I noticed you are using 2.43.1 which is a very old version.

ajohnston1219 commented 1 year ago

This is working now, even with the old version. I guess this was maybe just a temporary issue with ECR or a local network issue. Either way, I will close this as it appeared to be a temporary issue.

github-actions[bot] commented 1 year 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.

chudhunter commented 1 year ago

@ajohnston1219 problem has resurfaced again

ajohnston1219 commented 1 year ago

@chudhunter I was able to resolve this by restarting my docker engine the second time it happened to me. I think it is a transient issue with docker. You can go to ECR and verify the requested container is there, so not sure why its not able to find it. This may be a docker issue and not a CDK issue though.