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.52k stars 3.86k forks source link

(@aws-cdk/aws-lambda): layers property and addLayer() DockerLayerStack construct #27666

Open annguyen36 opened 11 months ago

annguyen36 commented 11 months ago

Hello team,

Main issue: Lambda functions packaged as container images do not support adding Lambda layers to the function configuration, but CDK docs lists layers property as one of DockerLayerStack's valid props and addLayer() is valid method.

From this closed issue: https://github.com/aws/aws-cdk/issues/14143 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)

What did you expect to have

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

If the layers property is not able to used to add layer to the DockerImageFunction construct, as well as the addLayer() method as this is something Lambda not support, I'm expecting these 2 are not listed in CDK documentation.

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

Originally posted by @annguyen36 in https://github.com/aws/aws-cdk/issues/14143#issuecomment-1771802154

sdpoueme commented 11 months ago

@annguyen36 Thanks for filing this. I am working on a similar problem. I think the issue need to be labeled as bug and triage to be visible in the queue.