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

cdk-assets: Ziping and uploading empty S3 folder #28086

Open
HFR1994 opened this issue Nov 21, 2023 · 0 comments
Open

cdk-assets: Ziping and uploading empty S3 folder #28086

HFR1994 opened this issue Nov 21, 2023 · 0 comments
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@HFR1994
Copy link

HFR1994 commented Nov 21, 2023

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

@HFR1994 HFR1994 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 21, 2023
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Nov 21, 2023
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. bug This issue is a bug. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2023
@khushail khushail self-assigned this Nov 30, 2023
@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Nov 30, 2023
@khushail khushail removed their assignment Dec 8, 2023
@khushail khushail removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 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

3 participants