@@ -4,6 +4,7 @@ const _ = require('lodash');
4
4
const BbPromise = require ( 'bluebird' ) ;
5
5
const path = require ( 'path' ) ;
6
6
const { isIntrinsic, translateLocalFunctionNames, trimAliasFromLambdaArn } = require ( '../../utils/aws' ) ;
7
+ const { getArnPartition } = require ( '../../utils/arn' ) ;
7
8
8
9
function getTaskStates ( states ) {
9
10
return _ . flatMap ( states , ( state ) => {
@@ -33,7 +34,8 @@ function sqsQueueUrlToArn(serverless, queueUrl) {
33
34
const region = match [ 1 ] ;
34
35
const accountId = match [ 2 ] ;
35
36
const queueName = match [ 3 ] ;
36
- return `arn:aws:sqs:${ region } :${ accountId } :${ queueName } ` ;
37
+ const partition = getArnPartition ( region ) ;
38
+ return `arn:${ partition } :sqs:${ region } :${ accountId } :${ queueName } ` ;
37
39
}
38
40
if ( isIntrinsic ( queueUrl ) ) {
39
41
if ( queueUrl . Ref ) {
@@ -91,7 +93,9 @@ function getDynamoDBArn(tableName) {
91
93
'Fn::Join' : [
92
94
':' ,
93
95
[
94
- 'arn:aws:dynamodb' ,
96
+ 'arn' ,
97
+ { Ref : 'AWS::Partition' } ,
98
+ 'dynamodb' ,
95
99
{ Ref : 'AWS::Region' } ,
96
100
{ Ref : 'AWS::AccountId' } ,
97
101
{
@@ -113,7 +117,9 @@ function getDynamoDBArn(tableName) {
113
117
'Fn::Join' : [
114
118
':' ,
115
119
[
116
- 'arn:aws:dynamodb' ,
120
+ 'arn' ,
121
+ { Ref : 'AWS::Partition' } ,
122
+ 'dynamodb' ,
117
123
{ Ref : 'AWS::Region' } ,
118
124
{ Ref : 'AWS::AccountId' } ,
119
125
`table/${ tableName } ` ,
@@ -132,7 +138,9 @@ function getBatchPermissions() {
132
138
'Fn::Join' : [
133
139
':' ,
134
140
[
135
- 'arn:aws:events' ,
141
+ 'arn' ,
142
+ { Ref : 'AWS::Partition' } ,
143
+ 'events' ,
136
144
{ Ref : 'AWS::Region' } ,
137
145
{ Ref : 'AWS::AccountId' } ,
138
146
'rule/StepFunctionsGetEventsForBatchJobsRule' ,
@@ -159,7 +167,9 @@ function getEcsPermissions() {
159
167
'Fn::Join' : [
160
168
':' ,
161
169
[
162
- 'arn:aws:events' ,
170
+ 'arn' ,
171
+ { Ref : 'AWS::Partition' } ,
172
+ 'events' ,
163
173
{ Ref : 'AWS::Region' } ,
164
174
{ Ref : 'AWS::AccountId' } ,
165
175
'rule/StepFunctionsGetEventsForECSTaskRule' ,
@@ -188,7 +198,7 @@ function getLambdaPermissions(state) {
188
198
const segments = functionName . split ( ':' ) ;
189
199
190
200
let functionArns ;
191
- if ( functionName . startsWith ( ' arn:aws:lambda' ) ) {
201
+ if ( functionName . match ( / ^ a r n : a w s ( - [ a - z ] + ) * : l a m b d a / ) ) {
192
202
// full ARN
193
203
functionArns = [
194
204
functionName ,
@@ -197,17 +207,17 @@ function getLambdaPermissions(state) {
197
207
} else if ( segments . length === 3 && segments [ 0 ] . match ( / ^ \d + $ / ) ) {
198
208
// partial ARN
199
209
functionArns = [
200
- { 'Fn::Sub' : `arn:aws :lambda:\${AWS::Region}:${ functionName } ` } ,
201
- { 'Fn::Sub' : `arn:aws :lambda:\${AWS::Region}:${ functionName } :*` } ,
210
+ { 'Fn::Sub' : `arn:\${AWS::Partition} :lambda:\${AWS::Region}:${ functionName } ` } ,
211
+ { 'Fn::Sub' : `arn:\${AWS::Partition} :lambda:\${AWS::Region}:${ functionName } :*` } ,
202
212
] ;
203
213
} else {
204
214
// name-only (with or without alias)
205
215
functionArns = [
206
216
{
207
- 'Fn::Sub' : `arn:aws :lambda:\${AWS::Region}:\${AWS::AccountId}:function:${ functionName } ` ,
217
+ 'Fn::Sub' : `arn:\${AWS::Partition} :lambda:\${AWS::Region}:\${AWS::AccountId}:function:${ functionName } ` ,
208
218
} ,
209
219
{
210
- 'Fn::Sub' : `arn:aws :lambda:\${AWS::Region}:\${AWS::AccountId}:function:${ functionName } :*` ,
220
+ 'Fn::Sub' : `arn:\${AWS::Partition} :lambda:\${AWS::Region}:\${AWS::AccountId}:function:${ functionName } :*` ,
211
221
} ,
212
222
] ;
213
223
}
@@ -236,13 +246,13 @@ function getLambdaPermissions(state) {
236
246
resource : [
237
247
{
238
248
'Fn::Sub' : [
239
- 'arn:aws :lambda:${AWS::Region}:${AWS::AccountId}:function:${functionArn}' ,
249
+ 'arn:${AWS::Partition} :lambda:${AWS::Region}:${AWS::AccountId}:function:${functionArn}' ,
240
250
{ functionArn } ,
241
251
] ,
242
252
} ,
243
253
{
244
254
'Fn::Sub' : [
245
- 'arn:aws :lambda:${AWS::Region}:${AWS::AccountId}:function:${functionArn}:*' ,
255
+ 'arn:${AWS::Partition} :lambda:${AWS::Region}:${AWS::AccountId}:function:${functionArn}:*' ,
246
256
{ functionArn } ,
247
257
] ,
248
258
} ,
@@ -282,7 +292,7 @@ function getStepFunctionsPermissions(state) {
282
292
action : 'events:PutTargets,events:PutRule,events:DescribeRule' ,
283
293
resource : {
284
294
'Fn::Sub' : [
285
- 'arn:aws :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule' ,
295
+ 'arn:${AWS::Partition} :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule' ,
286
296
{ } ,
287
297
] ,
288
298
} ,
@@ -296,15 +306,15 @@ function getCodeBuildPermissions(state) {
296
306
action : 'codebuild:StartBuild,codebuild:StopBuild,codebuild:BatchGetBuilds' ,
297
307
resource : {
298
308
'Fn::Sub' : [
299
- `arn:aws :codebuild:$\{AWS::Region}:$\{AWS::AccountId}:project/${ projectName } ` ,
309
+ `arn:\${AWS::Partition} :codebuild:$\{AWS::Region}:$\{AWS::AccountId}:project/${ projectName } ` ,
300
310
{ } ,
301
311
] ,
302
312
} ,
303
313
} , {
304
314
action : 'events:PutTargets,events:PutRule,events:DescribeRule' ,
305
315
resource : {
306
316
'Fn::Sub' : [
307
- 'arn:aws :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventForCodeBuildStartBuildRule' ,
317
+ 'arn:${AWS::Partition} :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventForCodeBuildStartBuildRule' ,
308
318
{ } ,
309
319
] ,
310
320
} ,
@@ -319,7 +329,7 @@ function getSageMakerPermissions(state) {
319
329
action : 'sagemaker:CreateTransformJob,sagemaker:DescribeTransformJob,sagemaker:StopTransformJob' ,
320
330
resource : {
321
331
'Fn::Sub' : [
322
- `arn:aws :sagemaker:$\{AWS::Region}:$\{AWS::AccountId}:transform-job/${ transformJobName } *` ,
332
+ `arn:\${AWS::Partition} :sagemaker:$\{AWS::Region}:$\{AWS::AccountId}:transform-job/${ transformJobName } *` ,
323
333
{ } ,
324
334
] ,
325
335
} ,
@@ -332,7 +342,7 @@ function getSageMakerPermissions(state) {
332
342
action : 'events:PutTargets,events:PutRule,events:DescribeRule' ,
333
343
resource : {
334
344
'Fn::Sub' : [
335
- 'arn:aws :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForSageMakerTransformJobsRule' ,
345
+ 'arn:${AWS::Partition} :events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForSageMakerTransformJobsRule' ,
336
346
{ } ,
337
347
] ,
338
348
} ,
@@ -352,7 +362,7 @@ function getEventBridgePermissions(state) {
352
362
action : 'events:PutEvents' ,
353
363
resource : [ ...eventBuses ] . map ( eventBus => ( {
354
364
'Fn::Sub' : [
355
- 'arn:aws :events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBus}' ,
365
+ 'arn:${AWS::Partition} :events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBus}' ,
356
366
{ eventBus } ,
357
367
] ,
358
368
} ) ) ,
@@ -399,7 +409,8 @@ function consolidatePermissionsByResource(permissions) {
399
409
400
410
function getIamPermissions ( taskStates ) {
401
411
return _ . flatMap ( taskStates , ( state ) => {
402
- switch ( state . Resource ) {
412
+ const resourceName = typeof state . Resource === 'string' ? state . Resource . replace ( / ^ a r n : a w s ( - [ a - z ] + ) * : / , 'arn:aws:' ) : state . Resource ;
413
+ switch ( resourceName ) {
403
414
case 'arn:aws:states:::sqs:sendMessage' :
404
415
case 'arn:aws:states:::sqs:sendMessage.waitForTaskToken' :
405
416
return getSqsPermissions ( this . serverless , state ) ;
@@ -452,7 +463,7 @@ function getIamPermissions(taskStates) {
452
463
return getEventBridgePermissions ( state ) ;
453
464
454
465
default :
455
- if ( isIntrinsic ( state . Resource ) || state . Resource . startsWith ( ' arn:aws:lambda' ) ) {
466
+ if ( isIntrinsic ( state . Resource ) || ! ! state . Resource . match ( / a r n : a w s ( - [ a - z ] + ) * : l a m b d a / ) ) {
456
467
const trimmedArn = trimAliasFromLambdaArn ( state . Resource ) ;
457
468
const functionArn = translateLocalFunctionNames . bind ( this ) ( trimmedArn ) ;
458
469
return [ {
0 commit comments