Skip to content

Commit

Permalink
fix(aws-elasticloadbalancingv2): cannot clear access logging bucket p…
Browse files Browse the repository at this point in the history
…refix (#15149)

This PR makes the empty bucket prefix explicit in cloud formation resource instead of omitting the entry all together.  Cloud Formation won't let you remove the prefix once it has has been set unless it is explicitly set this way.  

closes #14044
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ABevier authored Jun 24, 2021
1 parent ccc2e30 commit 2e93fb9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export abstract class BaseLoadBalancer extends Resource {
* environment-agnostic stacks. See https://docs.aws.amazon.com/cdk/latest/guide/environments.html
*/
public logAccessLogs(bucket: s3.IBucket, prefix?: string) {
prefix = prefix || '';
this.setAttribute('access_logs.s3.enabled', 'true');
this.setAttribute('access_logs.s3.bucket', bucket.bucketName.toString());
this.setAttribute('access_logs.s3.prefix', prefix);
Expand All @@ -247,7 +248,6 @@ export abstract class BaseLoadBalancer extends Resource {
throw new Error(`Cannot enable access logging; don't know ELBv2 account for region ${region}`);
}

prefix = prefix || '';
bucket.grantPut(new iam.AccountPrincipal(account), `${(prefix ? prefix + '/' : '')}AWSLogs/${Stack.of(this).account}/*`);

// make sure the bucket's policy is created before the ALB (see https://github.com/aws/aws-cdk/issues/1633)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ describe('tests', () => {
Key: 'access_logs.s3.bucket',
Value: { Ref: 'AccessLoggingBucketA6D88F29' },
},
{
Key: 'access_logs.s3.prefix',
Value: '',
},
),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ describe('tests', () => {
Key: 'access_logs.s3.bucket',
Value: { Ref: 'AccessLoggingBucketA6D88F29' },
},
{
Key: 'access_logs.s3.prefix',
Value: '',
},
),
});

Expand Down Expand Up @@ -479,4 +483,3 @@ describe('tests', () => {
});
});
});

0 comments on commit 2e93fb9

Please sign in to comment.