Skip to content

Commit 7a10a52

Browse files
committed
improve iam rule arn generation for s3 bucket
1 parent fb90490 commit 7a10a52

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,18 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa
120120
actions: ['s3:PutObject'],
121121
principals: [new ServicePrincipal('delivery.logs.amazonaws.com')],
122122
resources: [
123-
`arn:aws:s3:::${bucket.bucketName.toString()}/${prefix ? prefix + '/' : ''}AWSLogs/${
124-
Stack.of(this).account
125-
}/*`,
123+
bucket.arnForObjects(`${prefix ? prefix + '/' : ''}AWSLogs/${Stack.of(this).account}/*`),
126124
],
127125
conditions: {
128126
StringEquals: { 's3:x-amz-acl': 'bucket-owner-full-control' },
129127
},
130128
}),
131129
);
132-
133130
bucket.addToResourcePolicy(
134131
new PolicyStatement({
135132
actions: ['s3:GetBucketAcl'],
136133
principals: [new ServicePrincipal('delivery.logs.amazonaws.com')],
137-
resources: [`arn:aws:s3:::${bucket.bucketName.toString()}`],
134+
resources: [bucket.bucketArn],
138135
}),
139136
);
140137
}

packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/test.load-balancer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ export = {
121121
Effect: 'Allow',
122122
Principal: { Service: 'delivery.logs.amazonaws.com' },
123123
Resource: {
124-
'Fn::Join': ['', ['arn:aws:s3:::', { Ref: 'AccessLoggingBucketA6D88F29' },
125-
'/AWSLogs/', { Ref: 'AWS::AccountId' }, '/*']],
124+
'Fn::Join': ['', [{ 'Fn::GetAtt': ['AccessLoggingBucketA6D88F29', 'Arn'] }, '/AWSLogs/',
125+
{ Ref: 'AWS::AccountId' }, '/*']],
126126
},
127127
},
128128
{
129129
Action: 's3:GetBucketAcl',
130130
Effect: 'Allow',
131131
Principal: { Service: 'delivery.logs.amazonaws.com' },
132132
Resource: {
133-
'Fn::Join': ['', ['arn:aws:s3:::', { Ref: 'AccessLoggingBucketA6D88F29' }]],
133+
'Fn::GetAtt': ['AccessLoggingBucketA6D88F29', 'Arn'],
134134
},
135135
},
136136
],
@@ -194,16 +194,16 @@ export = {
194194
Effect: 'Allow',
195195
Principal: { Service: 'delivery.logs.amazonaws.com' },
196196
Resource: {
197-
'Fn::Join': ['', ['arn:aws:s3:::', { Ref: 'AccessLoggingBucketA6D88F29' },
198-
'/prefix-of-access-logs/AWSLogs/', { Ref: 'AWS::AccountId' }, '/*']],
197+
'Fn::Join': ['', [{ 'Fn::GetAtt': ['AccessLoggingBucketA6D88F29', 'Arn'] }, '/prefix-of-access-logs/AWSLogs/',
198+
{ Ref: 'AWS::AccountId' }, '/*']],
199199
},
200200
},
201201
{
202202
Action: 's3:GetBucketAcl',
203203
Effect: 'Allow',
204204
Principal: { Service: 'delivery.logs.amazonaws.com' },
205205
Resource: {
206-
'Fn::Join': ['', ['arn:aws:s3:::', { Ref: 'AccessLoggingBucketA6D88F29' }]],
206+
'Fn::GetAtt': ['AccessLoggingBucketA6D88F29', 'Arn'],
207207
},
208208
},
209209
],

0 commit comments

Comments
 (0)