Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda: Creating a LambdaFunction with DockerImageFunction, DockerImageAsset & DockerImageFunctionProps #26195

Open
ttais2017 opened this issue Jul 2, 2023 · 9 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@ttais2017
Copy link

Describe the bug

BUILD SUCCESSFUL in 23s
6 actionable tasks: 1 executed, 5 up-to-date

✨ Synthesis time: 23.57s

ADVANCED: start: Building 6e1cddd7d93b113a27547038f2962e6740fa861c33262dd8e6587ea19641a84b:current_account-current_region
ADVANCED: fail: docker login --username AWS --password-stdin https://279280305777.dkr.ecr.eu-west-1.amazonaws.com exited with error code 2: panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/docker/cli/cli/config/credentials.(*fileStore).Store(0xc0003cc0c0, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc0000404c8, ...}, ...})
/go/src/github.com/docker/cli/cli/config/credentials/file_store.go:55 +0x49
github.com/docker/cli/cli/config/credentials.(*nativeStore).Store(0xc0000081f8, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc0000404c8, ...}, ...})
/go/src/github.com/docker/cli/cli/config/credentials/native_store.go:95 +0xb5
github.com/docker/cli/cli/command/registry.runLogin({0x12a5cd8, 0xc0003841e0}, {{0xc0000404c0, 0x34}, {0xc000042118, 0x3}, {0xc0000d8900, 0x87c}, 0x1})
/go/src/github.com/docker/cli/cli/command/registry/login.go:156 +0x55d
github.com/docker/cli/cli/command/registry.NewLoginCommand.func1(0xc000005b00?, {0xc00013b240?, 0x1?, 0x4?})
/go/src/github.com/docker/cli/cli/command/registry/login.go:46 +0x72
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc000005b00, {0xc0003402e0, 0x4, 0x4})
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:940 +0x862
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:1068 +0x3bd
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:992
main.runDocker(0x0?)
/go/src/github.com/docker/cli/cmd/docker/docker.go:263 +0x4b7
main.main()
/go/src/github.com/docker/cli/cmd/docker/docker.go:274 +0x97

❌ Deployment failed: Error: Failed to build asset 6e1cddd7d93b113a27547038f2962e6740fa861c33262dd8e6587ea19641a84b:current_account-current_region
at Deployments.buildSingleAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:11476)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.buildAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:150805)
at async C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:137021

Failed to build asset 6e1cddd7d93b113a27547038f2962e6740fa861c33262dd8e6587ea19641a84b:current_account-current_region

Expected Behavior

The Docker Image should be created

Current Behavior

An error happens trying to get credentials for ECR:

fail: docker login --username AWS --password-stdin https://279280305777.dkr.ecr.eu-west-1.amazonaws.com exited with error code 2: panic: assignment to entry in nil map

Reproduction Steps

JavaCode:

` Map<String, String> environment = new HashMap<>();
environment.put(_USECASE_LAMBDA_DOCKER_NAME, "Customized by MR!");
environment.put("DEBUG", "true");
environment.put("ls", "true");
environment.put("times", "1000");

// Define the Docker image asset from the Dockerfile
DockerImageAsset dockerImageAsset = DockerImageAsset.Builder.create(this, "SbOnNewDocker")
        .directory("../05--lambda-docker")
        .build();

// Create the Lambda function using the Docker image
DockerImageFunctionProps functionProps = DockerImageFunctionProps.builder()
        .code(DockerImageCode.fromEcr(dockerImageAsset.getRepository()))
        .memorySize(1024) // Set the desired memory size
        .timeout(Duration.seconds(90))
        .environment(environment)
        .role(basicsProperties.dockerRole)
        .build();

properties.docker = new DockerImageFunction(this, "MyFunction", functionProps);`

Possible Solution

No response

Additional Information/Context

I'm using an AWS Profile for building and deploying. If the lambda function is commented out, the stack will be deployed succesfully. The error happens as soon the docker stuff will be executed. This means, the current problem is not related to the credentials I'm using via aws profile.

CDK CLI Version

2.86

Framework Version

No response

Node.js Version

9.5.1

OS

Windows

Language

Java

Language Version

No response

Other information

No response

@ttais2017 ttais2017 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 2, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jul 2, 2023
@pahud pahud changed the title Creating a LambdaFunction with DockerImageFunction, DockerImageAsset & DockerImageFunctionProps lambda: Creating a LambdaFunction with DockerImageFunction, DockerImageAsset & DockerImageFunctionProps Jul 3, 2023
@pahud pahud self-assigned this Jul 3, 2023
@pahud
Copy link
Contributor

pahud commented Jul 3, 2023

Have you tried DockerImageCode.fromImageAsset instead?

This works for me in TypeScript

    const func = new lambda.DockerImageFunction(this, 'Imagefunc', {
      code: lambda.DockerImageCode.fromImageAsset(path.join(__dirname, '../docker.d')),
    })

If you really need fromEcr, this works for me with tagOrDigest prop like this:

    const dockerImageAsset = new DockerImageAsset(this, 'ImageAsset', {
      directory: path.join(__dirname, '../docker.d'),
    })
    
    const func = new lambda.DockerImageFunction(this, 'Imagefunc', {
      // code: lambda.DockerImageCode.fromImageAsset(path.join(__dirname, '../docker.d')),
      code: lambda.DockerImageCode.fromEcr(dockerImageAsset.repository, {
        tagOrDigest: dockerImageAsset.imageTag,
      })
    })

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 3, 2023
@pahud pahud removed their assignment Jul 3, 2023
@pahud
Copy link
Contributor

pahud commented Jul 3, 2023

Interesting your error message seems a golang error.

Are you deploying this manually with CDK CLI from a local env?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 3, 2023
@ttais2017
Copy link
Author

Hi Pahud,

Thanks for your quick feedback.

I tried once with your suggestion (DockerImageCode.fromImageAsset)

The behaviour was the same. The same error. Look the output:


ADVANCED:  success: Published 79a210a49be02511e5fd475777e57dd2b515c7de73c3d93c27f1bf1ab186c746:current_account-current_region                                                            
ADVANCED:  success: Published 675f6e3b4f93b056702dcd5e7382a6be803a6bd65179f29903bcb69929f5003b:current_account-current_region                                                            
ADVANCED:  success: Published f70a0c153fce453690c831fc9acbf714969f0e1c19e1ee017cbedb45f662e724:current_account-current_region                                                            
ADVANCED:  fail: docker login --username AWS --password-stdin https://279759165626.dkr.ecr.eu-central-1.amazonaws.com exited with error code 2: panic: assignment to entry in nil map    
                                                                                                                                                                                         
goroutine 1 [running]:                                                                                                                                                                   
github.com/docker/cli/cli/config/credentials.(*fileStore).Store(0xc00060ad40, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc00011a148, ...}, ...})                                
        /go/src/github.com/docker/cli/cli/config/credentials/file_store.go:55 +0x49                                                                                                      
github.com/docker/cli/cli/config/credentials.(*nativeStore).Store(0xc000406078, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc00011a148, ...}, ...})                              
        /go/src/github.com/docker/cli/cli/config/credentials/native_store.go:95 +0xb5                                                                                                    
github.com/docker/cli/cli/command/registry.runLogin({0x1d05cd8, 0xc0003aa0f0}, {{0xc00011a140, 0x37}, {0xc00011e0a8, 0x3}, {0xc000174900, 0x8a0}, 0x1})                                  
        /go/src/github.com/docker/cli/cli/command/registry/login.go:156 +0x55d                                                                                                           
github.com/docker/cli/cli/command/registry.NewLoginCommand.func1(0xc000005b00?, {0xc000434100?, 0x1?, 0x4?})                                                                             
        /go/src/github.com/docker/cli/cli/command/registry/login.go:46 +0x72                                                                                                             
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc000005b00, {0xc00008cd80, 0x4, 0x4})                                                                           
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:940 +0x862                                                                                                
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)                                                                                                    
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:1068 +0x3bd                                                                                               
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)                                                                                                              
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:992                                                                                                       
main.runDocker(0x0?)                                                                                                                                                                     
        /go/src/github.com/docker/cli/cmd/docker/docker.go:263 +0x4b7                                                                                                                    
main.main()                                                                                                                                                                              
        /go/src/github.com/docker/cli/cmd/docker/docker.go:274 +0x97                                                                                                                     
                                                                                                                                                                                         
 ❌ Deployment failed: Error: Failed to build asset f136923159c20e1a4158cbe775a7d300202612561b21fada800a665f3f22c3c4:current_account-current_region                                       
    at Deployments.buildSingleAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:11476)                                                      
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)                                                                                                        
    at async Object.buildAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:150805)                                                          
    at async C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:137021                                                                              
                                                                                                                                                                                         
Failed to build asset f136923159c20e1a4158cbe775a7d300202612561b21fada800a665f3f22c3c4:current_account-current_region                                                                    
                                          

w.r.t your other question: I'm deploying with cdk deploy:

npx aws-cdk deploy MY_STACK --profile assets-repository

@easywang
Copy link

easywang commented Jul 5, 2023

I have the same error log with docker login.
My Docker Desktop version is 4.21.0,and I updates it to 4.21.1. It's work!~

@ttais2017
Copy link
Author

ttais2017 commented Jul 6, 2023

I updated my Docker and it looks like :

image

I tried once to deploy, but I'm getting the same error :(

image

hier in text-form

`BUILD SUCCESSFUL in 37s
6 actionable tasks: 1 executed, 5 up-to-date

✨ Synthesis time: 38.17s

ADVANCED: start: Building d37ffa7c6dbeadfeecbaf54a982293c60504d4a2717881f99bbf748c4cfd4d4c:current_account-current_region
ADVANCED: fail: docker login --username AWS --password-stdin https://279759165626.dkr.ecr.eu-central-1.amazonaws.com exited with error code 2: panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/docker/cli/cli/config/credentials.(*fileStore).Store(0xc00007e220, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc000040408, ...}, ...})
/go/src/github.com/docker/cli/cli/config/credentials/file_store.go:55 +0x49
github.com/docker/cli/cli/config/credentials.(*nativeStore).Store(0xc000494078, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc000040408, ...}, ...})
/go/src/github.com/docker/cli/cli/config/credentials/native_store.go:95 +0xb5
github.com/docker/cli/cli/command/registry.runLogin({0x1375cd8, 0xc0003841e0}, {{0xc000040400, 0x37}, {0xc000042118, 0x3}, {0xc0000d8900, 0x8a0}, 0x1})
/go/src/github.com/docker/cli/cli/command/registry/login.go:156 +0x55d
github.com/docker/cli/cli/command/registry.NewLoginCommand.func1(0xc000005b00?, {0xc0004721c0?, 0x1?, 0x4?})
/go/src/github.com/docker/cli/cli/command/registry/login.go:46 +0x72
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc000005b00, {0xc000124740, 0x4, 0x4})
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:940 +0x862
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:1068 +0x3bd
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
/go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:992
main.runDocker(0x0?)
/go/src/github.com/docker/cli/cmd/docker/docker.go:263 +0x4b7
main.main()
/go/src/github.com/docker/cli/cmd/docker/docker.go:274 +0x97

❌ Deployment failed: Error: Failed to build asset d37ffa7c6dbeadfeecbaf54a982293c60504d4a2717881f99bbf748c4cfd4d4c:current_account-current_region
at Deployments.buildSingleAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:11476)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.buildAsset (C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:150805)
at async C:\Users\Rojas-GonzálezDrIngM\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:415:137021

Failed to build asset d37ffa7c6dbeadfeecbaf54a982293c60504d4a2717881f99bbf748c4cfd4d4c:current_account-current_region`

@rookwood101
Copy link

rookwood101 commented Jul 18, 2023

I was able to fix this by editing ~/.docker/config.json
Somehow it was initialised in a way that meant docker couldn't handle it, so I changed from:

{
	"auths": null,
	...
}

to

{
	"auths": {},
	...
}

@ttais2017
Copy link
Author

ttais2017 commented Jul 18, 2023 via email

@rookwood101
Copy link

rookwood101 commented Jul 18, 2023 via email

@japerr
Copy link

japerr commented Jul 26, 2023

This does appear to be a docker issue. It's been fixed and merged, probably in the next docker update

docker/cli#4414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

5 participants