Skip to content

(core): Stack assets are no longer bundled if contained in a stage #21162

@flaminscotsman

Description

@flaminscotsman

Describe the bug

The changes in #19950 altered the logic for which stacks are considered eligible for bundling.

  • The bundlingRequired property on a stack uses minimatch to determine if the stack is eligible for bundling based on a pattern set in the context (cxapi.BUNDLING_STACKS)
  • When wrapped in a stage, the stack path is considered "path-like" to minimatch
  • This means the default bundling pattern ("*") no longer matches any of the stacks in that stage as minimatch expects ** to be used as a wildcard for a "path"

The bundled stacks property is set (or defaulted) multiple times within the code, but when running through the CLI, https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/settings.ts#L255 is used. This sets the filter to either the provided pattern(s) if --exclusively is provided, otherwise defaults to ['*']

Expected Behavior

All appropriate assets are bundled ready for publishing

Current Behavior

Assets are not bundled - instead the asset source path is used

{
  "version": "20.0.0",
  "files": {
    "8f818b52da0f5958735dc2f0ea7f60cc3ff5db96beb0c8aae6c8be68e1c4b1fb": {
      "source": {
        "path": "/src",
        "packaging": "zip"
      },
      "destinations": {
        "current_account-current_region": {
          "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
          "objectKey": "8f818b52da0f5958735dc2f0ea7f60cc3ff5db96beb0c8aae6c8be68e1c4b1fb.zip",
          "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
        }
      }
    }
  }
}

Reproduction Steps

Generate a CDK app containing a stack wrapped in a stage containing at least one bundled asset
cdk synth (or cdk deploy) will no longer generate the bundled asset in the cdk.out folder, nor will the assets.json manifest contain the correct definition for the asset

A quick app can be found at https://github.com/flaminscotsman/cdk-bundle-failure

Possible Solution

Revert to the previous logic of replacing / with - to prevent minimatch interpreting it as a path

Alternatively move to non-path-aware matching logic

Additional Information/Context

No response

CDK CLI Version

2.32.0 (build 00e0c2d)

Framework Version

2.32.0

Node.js Version

16

OS

Windows (also reproduced on linux)

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions