Skip to content

fix: resolve asset staging timing issue and use dynamic region for multi-region StackSets#881

Open
spensireli wants to merge 1 commit into
cdklabs:mainfrom
spensireli:main
Open

fix: resolve asset staging timing issue and use dynamic region for multi-region StackSets#881
spensireli wants to merge 1 commit into
cdklabs:mainfrom
spensireli:main

Conversation

@spensireli

Copy link
Copy Markdown

Summary

This PR fixes two issues with the StackSetStackSynthesizer that prevent proper multi-region StackSet deployments with assets (e.g., Lambda functions):

1. Asset Staging Timing Issue

The addFileAsset method was using Source.asset() with a local file path that doesn't exist during synthesis. This fix delegates asset staging to the parent stack's synthesizer first, then uses
Source.bucket() to reference the staged asset in S3.

Changes:

  • Delegate asset staging to the parent stack's synthesizer via parentStack.synthesizer.addFileAsset(asset)
  • Create a lazy reference to the parent's asset bucket using Bucket.fromBucketName()
  • Use Source.bucket() to reference the asset from S3 instead of local file path
  • This follows the same pattern as ProductStackSynthesizer in aws-cdk-lib

2. Dynamic Region Reference for Multi-Region Deployments

The bucket name was being constructed using this.boundStack.region which hardcodes the parent stack's region at synthesis time. For multi-region StackSets, each target region needs to resolve the
bucket name dynamically.

Changes:

  • Changed from Fn.join('-', [this.assetBucketPrefix, this.boundStack.region])
  • To Fn.join('-', [this.assetBucketPrefix, Fn.ref('AWS::Region')])
  • This allows the bucket name to resolve dynamically at deployment time in each target region

How It Works

When deploying StackSets with Lambda functions or other assets across multiple regions:

  1. Assets are staged to the parent stack's asset bucket
  2. BucketDeployment copies assets to regional buckets (e.g., my-assets-us-east-1, my-assets-us-west-2)
  3. The StackSet template uses ${AWS::Region} intrinsic so each target region fetches from its local bucket

Test Plan

  • Existing unit tests pass
  • Integration tests pass
  • Manual testing with multi-region StackSet deployment with Lambda assets

Replace hardcoded 'arn:aws:' / 'amazonaws.com' with Stack.formatArn and
Stack.urlSuffix so self-managed StackSets resolve the correct partition
(e.g. aws-us-gov) at deployment time.

Also fix asset staging in StackSetStackSynthesizer: delegate staging to
the parent stack's synthesizer and reference the staged object via
Source.bucket() instead of Source.asset() on a not-yet-existing local
path, and derive the per-region asset bucket name from Fn.ref('AWS::Region')
so it resolves in each target region at deploy time.

Add aws-us-gov to the integ test target-partitions, regenerate the integ
snapshot, and add unit tests covering the partition-aware ARN / URL suffix.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
auto-merge was automatically disabled July 23, 2026 23:58

Head branch was pushed to by a user without write access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant