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

fix(s3-deployment): fails when destinationKeyPrefix is a token with a long string representation #22163

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ export class BucketDeployment extends Construct {
// the tag key limit of 128
// '/this/is/a/random/key/prefix/that/is/a/lot/of/characters/do/we/think/that/it/will/ever/be/this/long?????'
// better to throw an error here than wait for CloudFormation to fail
if (tagKey.length > 128) {
throw new Error('The BucketDeployment construct requires that the "destinationKeyPrefix" be <=104 characters');
if (!cdk.Token.isUnresolved(tagKey) && tagKey.length > 128) {
throw new Error('The BucketDeployment construct requires that the "destinationKeyPrefix" be <=104 characters.');
}

/*
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,28 @@ test('throws if destinationKeyPrefix is too long', () => {

});

test('skips destinationKeyPrefix validation if token', () => {

// GIVEN
const stack = new cdk.Stack();
const bucket = new s3.Bucket(stack, 'Dest');

// WHEN
// trick the cdk into creating a very long token
const prefixToken = cdk.Token.asString(5, { displayHint: 'longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong' });
new s3deploy.BucketDeployment(stack, 'DeployWithVpc2', {
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
destinationBucket: bucket,
destinationKeyPrefix: prefixToken,
memoryLimit: 256,
});

Template.fromStack(stack).hasResourceProperties('Custom::CDKBucketDeployment', {
DestinationBucketKeyPrefix: 5,
});

});

test('bucket has multiple deployments', () => {

// GIVEN
Expand Down