cdklabs / cdk-stacksets

Apache License 2.0
91 stars 14 forks source link

Confusion about File Assets and regions #171

Open pedromtcosta opened 1 year ago

pedromtcosta commented 1 year ago

I defined the following structure for my Stack Set:

const app = new cdk.App();

const stack = new cdk.Stack(app);

new MyStackWithSharedResources(app, 'MyStackWithSharedResources');
const myMultiRegionStackSetStack = new MyMultiRegionStackSetStack(stack, 'MyMultiRegionStackSetStack');

new StackSet(stack, 'MyStackSet', {
  target: StackSetTarget.fromAccounts({
    accounts: ['11111111111'],
    regions: ['us-east-1'],
  }),
  template: StackSetTemplate.fromStackSetStack(myMultiRegionStackSetStack),
  capabilities: [
    Capability.IAM
  ],
  deploymentType: DeploymentType.selfManaged({
    adminRole: iam.Role.fromRoleArn(
      stack,
      'YoroiBackendZeroStackSetAdminRole',
      'arn:aws:iam::11111111111:role/AWSCloudFormationStackSetAdministrationRole',
    )
  })
});

when I try deploying it with cdk deploy --all, I get the error:

An Asset Bucket must be provided to use File Assets

Then I create a bucket on the eu-central-1 region and set the assetBucket on my StackSetStack:

export class MyMultiRegionStackSetStack extends StackSetStack {
  constructor(scope: Construct, id: string) {
    super(scope, id, {
      assetBucket: s3.Bucket.fromBucketArn(
        scope,
        'AssetBucket',
        'arn:aws:s3:::my-assets-bucket'
      )
    });
  }
}

but now I get the error:

Error occurred while GetObject. S3 Error Code: PermanentRedirect. S3 Error Message: The bucket is in this region: eu-central-1. Please use this region to retry the request

Changing my StackSet target to eu-central-1 fixes the problem, but it will simply come back when I start adding more regions.

How to get away from this situation where I cannot leave assetBucket empty because of the first error, but I also cannot set a value to it because the deployment will fail when I am in a different region than the bucket?

corymhall commented 1 year ago

@josh-demuth

josh-demuth commented 1 year ago

thank you for reporting this. we are working on a fix

josh-demuth commented 10 months ago

this should be resolved by https://github.com/cdklabs/cdk-stacksets/pull/325. we will update once we can get it merged.

maherio commented 1 month ago

I'm getting a similar but slightly different error: PermanentRedirect. S3 Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint (frustratingly the logs/output don't actually specify what the endpoint should be).

Is it possible we're not formatting the s3 bucket endpoint up to current recommendations? i'm reading you should generally access a bucket by one of the following:

but it appears this is actually using https://s3.<bucket name>