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

(@aws-cdk/aws-lambda): validate that layers must not be used with container functions #14143

Closed
ghost opened this issue Apr 13, 2021 · 4 comments · Fixed by #15037
Closed

(@aws-cdk/aws-lambda): validate that layers must not be used with container functions #14143

ghost opened this issue Apr 13, 2021 · 4 comments · Fixed by #15037
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@ghost
Copy link

ghost commented Apr 13, 2021

Although Lambda with Docker images does not support layers, one could set layers in CDK (used version 1.95.1). The official documentation for CDK 1.98.0 is still offering the construct prop (see https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.DockerImageFunction.html).

Using this option leads to an unsuccessful deployment with the following message in CFN:
Lambda layers are not supported for functions created with container images. (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 00f7e41e-d341-4a53-b67f-73cc6dbab507; Proxy: null)

Reproduction Steps

Define a Lambda function as below:
const myFunction = new lambda.DockerImageFunction(this, 'myDockerFunction', { code: lambda.DockerImageCode.fromImageAsset('./src/myFunctionCode/'), tracing: lambda.Tracing.ACTIVE, deadLetterQueueEnabled: true, memorySize: 1024, timeout: cdk.Duration.seconds(10), logRetention: 14 });

What did you expect to happen?

I expect that unsupported construct options are not implemented. This might lead to confusion during implementation when consulting the docs.

What actually happened?

For the error message of CFN, please see above.

Environment

  • CDK CLI Version : 1.95.1 (tested), 1.98.0 still in docs and probably available
  • Framework Version: 1.95.1 (tested), 1.98.0 still in docs and probably available
  • Node.js Version: independend
  • OS : independend
  • Language (Version): all

This is 🐛 Bug Report

@ghost ghost added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 13, 2021
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 13, 2021
@nija-at
Copy link
Contributor

nija-at commented Apr 15, 2021

Hi @RigoIce - thanks for filing this issue.

The best we can do here is to add a validation on the cdk side when layers are configured when using DockerImageFunction. That would mean you will get this error during synthesis and not have to wait until deployment.

Trying to model all the different combinations of properties allowed in the various scenarios will make the code hard to maintain.

@nija-at nija-at changed the title (@aws-cdk/aws-lambda): Option for unallowed layers in container functions (@aws-cdk/aws-lambda): validate that layers must not be used with container functions Apr 15, 2021
@nija-at nija-at added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 15, 2021
@ghost
Copy link
Author

ghost commented Apr 15, 2021

Hi @nija-at. Thanks for taking care.

I understand the maintenance point of view. Having the build or even local synthesis failing before CFN complains would be very helpful as it could save a lot of time. Especially in migration phases as the options are so similar. As soon as one know this, it's okay. But anyways, I love when synthesis makes me aware of mistakes early. 😄

@mergify mergify bot closed this as completed in #15037 Jun 10, 2021
mergify bot pushed a commit that referenced this issue Jun 10, 2021
…nctions (#15037)

This change fixes #14143 by throwing an error during synthesis if layers are used in a container function.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️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.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
…nctions (aws#15037)

This change fixes aws#14143 by throwing an error during synthesis if layers are used in a container function.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@annguyen36
Copy link

annguyen36 commented Oct 19, 2023

Hello team, although there is an error added to the synthesis step when creating container function with layers, I found the issue with addLayer() method when trying to add the layer to the container function, it was passed the synthesize
step and failed at stack deployment:

❌ Deployment failed: Error: The stack named DockerLayerStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Please don't provide Handler or Runtime or Layer when the intended function PackageType is Image. (Service: Lambda, Status Code: 400)" HandlerErrorCode: InvalidRequest)

doc: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.DockerImageFunction.html#addwbrlayerslayers

Also, if the layers property is not suppose to be added to the DockerImageFunction construct, as well as the addLayer() method as this is something Lambda not support, why this listed under the CDK document as an available property of this construct?

This creates a lot of confusion, please consider to revise this document.

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/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants