aws-cdk: ‼️ (aws-lambda-python): SAM - CDK integration is broken in CDK V2.4.0
What is the problem?
There is a new change in CDK Version 2.4.0 that makes the bundled assets to be created under the folder structure as following:
├── <asset root>
│ └── asset-input
│ ├── asset files
The issue is SAM expects to get the asset location in metadata property aws:asset:path, so SAM can read the Lambda Function source code, so the customers can do local testing, but in the new Version, the value of the added metadata is the path till the Asset root directory (till the <Asset Hash>), although it should be (<Asset Hash>/asset-input)
For an application that contains a PythonFunction, This is the directory structure after running cdk synth using version 2.4.0
147dda696921:cdk_app melasmar$ cdk --version
2.4.0 (build 993f14d)
147dda696921:cdk_app melasmar$ cd cdk.out
147dda696921:cdk.out melasmar$ tree
.
├── CDKV2SupportDemoStack.assets.json
├── CDKV2SupportDemoStack.template.json
├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda5
│ └── asset-input
│ ├── __init__.py
│ └── app.py
├── cdk.out
├── manifest.json
└── tree.json
and this is the synthesized template:
"MyFunction3BAA72D1": {
"Type": "AWS::Lambda::Function",
"Properties": {
............
},
"DependsOn": [
"MyFunctionServiceRole3C357FF2"
],
"Metadata": {
"aws:cdk:path": "CDKV2SupportDemoStack/MyFunction/Resource",
"aws:asset:path": "asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda5",
"aws:asset:is-bundled": true,
"aws:asset:property": "Code"
}
and this is the output in case of using CDK version 2.3.0
147dda696921:cdk_app melasmar$ cdk --version
2.3.0 (build beaa5b2)
147dda696921:cdk_app melasmar$ cd cdk.out
147dda696921:cdk.out melasmar$ tree
.
├── CDKV2SupportDemoStack.assets.json
├── CDKV2SupportDemoStack.template.json
├── asset.8f47b59bc8d67146c1b3fdd46c077e64cf2e0021298beb44f424619eeaaad8d0
│ ├── __init__.py
│ └── app.py
├── cdk.out
├── manifest.json
└── tree.json
and this is the synthesized template:
"MyFunction3BAA72D1": {
"Type": "AWS::Lambda::Function",
"Properties": {
.........
},
"DependsOn": [
"MyFunctionServiceRole3C357FF2"
],
"Metadata": {
"aws:cdk:path": "CDKV2SupportDemoStack/MyFunction/Resource",
"aws:asset:path": "asset.8f47b59bc8d67146c1b3fdd46c077e64cf2e0021298beb44f424619eeaaad8d0",
"aws:asset:is-bundled": true,
"aws:asset:property": "Code"
}
},
Reproduction Steps
- create a simple CDK stack that contains a PythonFunction.
- run
cdk synth - check the synthesized template, and the bundled assets directory
What did you expect to happen?
The value of the added aws:asset:path metadata property should be the location of the source code of the bundled assets.
What actually happened?
The value of the added aws:asset:path metadata property is the root asset directory.
CDK CLI Version
2.4.0
Framework Version
No response
Node.js Version
v14.15.4
OS
mac os
Language
Typescript
Language Version
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 20 (11 by maintainers)
Commits related to this issue
- fix(lambda-python): asset files are generated inside the 'asset-input' folder (#18306) Changes the asset structure from: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda... — committed to aws/aws-cdk by otaviomacedo 2 years ago
- fix(lambda-python): asset files are generated inside the 'asset-input' folder (#18306) Changes the asset structure from: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda... — committed to aws/aws-cdk by otaviomacedo 2 years ago
- fix(lambda-python): bundle asset files correctly Fixes #18301. — committed to setu4993/aws-cdk by setu4993 2 years ago
- fix(lambda-python): bundle asset files correctly Fixes #18301. — committed to setu4993/aws-cdk by setu4993 2 years ago
- fix(lambda-python): bundle asset files correctly Fixes #18301. — committed to setu4993/aws-cdk by setu4993 2 years ago
- fix(lambda-python): asset files are generated inside the 'asset-input' folder (#18306) Changes the asset structure from: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda... — committed to aws/aws-cdk by otaviomacedo 2 years ago
- fix(lambda-python): bundle asset files correctly (#18335) Asset files are incorrectly being bundled under the `asset-input` directory instead of the root of the bundle. To also copy over hidden file... — committed to aws/aws-cdk by setu4993 2 years ago
- fix(lambda-python): asset files are generated inside the 'asset-input' folder (#18306) Changes the asset structure from: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda... — committed to TikiTDO/aws-cdk by otaviomacedo 2 years ago
- fix(lambda-python): bundle asset files correctly (#18335) Asset files are incorrectly being bundled under the `asset-input` directory instead of the root of the bundle. To also copy over hidden file... — committed to TikiTDO/aws-cdk by setu4993 2 years ago
@corymhall can you reopen this? It’s still an issue.
@corymhall I am having this issue currently, with aws-cdk-lib: 2.40.0 and aws-cdk/aws-lambda-python-alpha:2.40.0a0 (typescript stack with a lambdaPython).
Currently working with the following: aws-cdk-lib==2.5.0 aws-cdk.aws-lambda-python-alpha==2.3.0a0
Thanks @njlynch … This issue also exist in versions 1.137.0, and 1.138.0. Are you going to release a fix for these versions as well?
@raincoastchris thanks for calling this out mergify closed the issue automatically. I’m reopening, as the actual fix will be available in the next release.
See also this comment from @chrispykim: https://github.com/aws/aws-cdk/pull/18082#issuecomment-1008442363
I might be doing something wrong, but I get the synth failures due to the issue above on 1.138.0 and 1.138.1 (python cdk). 1.137.0 works correctly.