aws / aws/aws-cdk

cdk-assets: Ziping and uploading empty S3 folder

Open
#28,086 0 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-s3 bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

I recently created my own CodePipeline with a step to synth the CDK folder and upload whatever need to be uploaded using cdk-assets, here is my synth definition:

```
iaac_build_project = codebuild.Project(self, "IaaCBuildProject",
environment=codebuild.BuildEnvironment(
build_image=codebuild.LinuxBuildImage.AMAZON_LINUX_2_5
),
build_spec=codebuild.BuildSpec.from_object({
"version": "0.2",
"phases": {
"install": {
"runtime-versions": {
"nodejs": 18,
"python": "3.11"
},
"commands": [
"npm install -g aws-cdk",
"pip install -r requirements.txt"
]
},
"build": {
"commands": [
"npx cdk synth -c TargetStack=$STACK_NAME",
]
}
},
"artifacts": {
"files": "cdk.out/*"
}
}),
role=code_build_role
)
```

And this is the step that uses cdk-assets

```
cdk_deploy_assets = codebuild.Project(self, "CDKDeployAssets",
environment=codebuild.BuildEnvironment(
build_image=codebuild.LinuxBuildImage.AMAZON_LINUX_2_5
),
build_spec=codebuild.BuildSpec.from_object({
"version": "0.2",
"phases": {
"install": {
"runtime-versions": {
"nodejs": 18,
"python": "3.11"
},
"commands": [
"npm install -g cdk-assets@latest",
"tmpfile=/tmp/aws-session-file",
"aws sts assume-role --role-arn $CDK_ROLE --role-session-name `whoami`-`date +%d%m%y`-session > $tmpfile",
"export AWS_ACCESS_KEY_ID=`cat $tmpfile|jq -c '.Credentials.AccessKeyId'|tr -d '\"'`",
"export AWS_SECRET_ACCESS_KEY=`cat $tmpfile |jq -c '.Credentials.SecretAccessKey'|tr -d '\"'`",
"export AWS_SESSION_TOKEN=`cat $tmpfile|jq -c '.Credentials.SessionToken'|tr -d '\"'`",
]
},
"build": {
"commands": [
"export AWS_PROFILE=assumed-role",
"cat cdk.out/$STACK_NAME.assets.json | jq 'del(.'$KEY')' > cdk.out/assets.json",
"cat cdk.out/assets.json",
"cdk-assets publish -p cdk.out/assets.json"
]
}
}
}),
role=code_build_role
)
```

Althought logs show that assets are being publish, whenever I check S3 zip folder are empty. Any ideas? My folder only contain a single index.py file its defined using the following snippet:
```

lbd_function = lambda_.Function(self, "lbdFunction",
code=lambda_.Code.from_asset("./lambda/path_to_code"),
handler="index.handler",
timeout=Duration.seconds(30),
runtime=lambda_.Runtime.PYTHON_3_11,
memory_size=256,
role=lambda_role,
function_name="lbd_function"
)
```

### Expected Behavior

Uploaded folder are zipped with the index.py file

### Current Behavior

Uploaded folder are zipped with no contents

### Reproduction Steps

Create a CodePipeline and use the definitions provided up top.

### Possible Solution

_No response_

### Additional Information/Context

It's seems this doesn't happen on my local, any ideas?

### CDK CLI Version

2.110.0

### Framework Version

_No response_

### Node.js Version

18

### OS

Amazon Linux 2023

### Language

Python

### Language Version

Python 3.11

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the generated cdk.out/$STACK_NAME.assets.json and the derived cdk.out/assets.json, then inspect the cdk-assets publish step in the provided CodeBuild definition. Compare the local and Amazon Linux 2023 outputs for the lambda/path_to_code asset. Done means cdk-assets publishes a zip containing index.py rather than an empty folder.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, python
Domain
cloud, devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.