Skip to content

Commit a9ff5db

Browse files
fix: s3 perm requires ARN not bucket name
1 parent ca8dcf0 commit a9ff5db

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/package/s3/compileIamRoleToS3.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
const _ = require('lodash')
44

5+
function convertToArn(bucket) {
6+
// bucket can be either a Ref, or a string (bucket name)
7+
if (bucket.Ref) {
8+
const logicalId = bucket.Ref
9+
return {
10+
'Fn::GetAtt': [logicalId, 'Arn']
11+
}
12+
} else {
13+
return `arn:aws:s3:::${bucket}`
14+
}
15+
}
16+
517
module.exports = {
618
compileIamRoleToS3() {
719
const bucketActions = _.flatMap(this.getAllServiceProxies(), (serviceProxy) => {
@@ -29,7 +41,7 @@ module.exports = {
2941
'Fn::Sub': [
3042
'${bucket}/*',
3143
{
32-
bucket
44+
bucket: convertToArn(bucket)
3345
}
3446
]
3547
}

lib/package/s3/compileIamRoleToS3.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('#compileIamRoleToS3()', () => {
102102
'Fn::Sub': [
103103
'${bucket}/*',
104104
{
105-
bucket: 'myBucket'
105+
bucket: 'arn:aws:s3:::myBucket'
106106
}
107107
]
108108
}
@@ -114,7 +114,7 @@ describe('#compileIamRoleToS3()', () => {
114114
'Fn::Sub': [
115115
'${bucket}/*',
116116
{
117-
bucket: 'myBucket'
117+
bucket: 'arn:aws:s3:::myBucket'
118118
}
119119
]
120120
}
@@ -127,7 +127,7 @@ describe('#compileIamRoleToS3()', () => {
127127
'${bucket}/*',
128128
{
129129
bucket: {
130-
Ref: 'MyBucket'
130+
'Fn::GetAtt': ['MyBucket', 'Arn']
131131
}
132132
}
133133
]
@@ -140,7 +140,7 @@ describe('#compileIamRoleToS3()', () => {
140140
'Fn::Sub': [
141141
'${bucket}/*',
142142
{
143-
bucket: 'myBucketV2'
143+
bucket: 'arn:aws:s3:::myBucketV2'
144144
}
145145
]
146146
}

0 commit comments

Comments
 (0)