diff --git a/lib/plugins/aws/package/compile/events/sqs/index.js b/lib/plugins/aws/package/compile/events/sqs/index.js index b500c7771..3a4904e27 100644 --- a/lib/plugins/aws/package/compile/events/sqs/index.js +++ b/lib/plugins/aws/package/compile/events/sqs/index.js @@ -85,6 +85,9 @@ class AwsCompileSQSEvents { return EventSourceArn['Fn::GetAtt'][0]; } else if (EventSourceArn['Fn::ImportValue']) { return EventSourceArn['Fn::ImportValue']; + } else if (EventSourceArn['Fn::Join']) { + // [0] is the used delimiter, [1] is the array with values + return EventSourceArn['Fn::Join'][1].slice(-1).pop(); } return EventSourceArn.split(':').pop(); }()); diff --git a/lib/plugins/aws/package/compile/events/sqs/index.test.js b/lib/plugins/aws/package/compile/events/sqs/index.test.js index a251c9d87..2e21dfa15 100644 --- a/lib/plugins/aws/package/compile/events/sqs/index.test.js +++ b/lib/plugins/aws/package/compile/events/sqs/index.test.js @@ -391,18 +391,29 @@ describe('AwsCompileSQSEvents', () => { arn: { 'Fn::ImportValue': 'ForeignQueue' }, }, }, + { + sqs: { + arn: { + 'Fn::Join': [ + ':', [ + 'arn', 'aws', 'sqs', { + Ref: 'AWS::Region', + }, + { + Ref: 'AWS::AccountId', + }, + 'MyQueue', + ], + ], + }, + }, + }, ], }, }; awsCompileSQSEvents.compileSQSEvents(); - expect(awsCompileSQSEvents.serverless.service - .provider.compiledCloudFormationTemplate.Resources - .FirstEventSourceMappingSQSSomeQueue.Properties.EventSourceArn - ).to.deep.equal( - { 'Fn::GetAtt': ['SomeQueue', 'Arn'] } - ); expect(awsCompileSQSEvents.serverless.service .provider.compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution .Properties.Policies[0].PolicyDocument.Statement[0] @@ -424,18 +435,62 @@ describe('AwsCompileSQSEvents', () => { { 'Fn::ImportValue': 'ForeignQueue', }, + { + 'Fn::Join': [ + ':', + [ + 'arn', + 'aws', + 'sqs', + { + Ref: 'AWS::Region', + }, + { + Ref: 'AWS::AccountId', + }, + 'MyQueue', + ], + ], + }, ], } ); + expect(awsCompileSQSEvents.serverless.service + .provider.compiledCloudFormationTemplate.Resources + .FirstEventSourceMappingSQSSomeQueue.Properties.EventSourceArn + ).to.deep.equal( + { 'Fn::GetAtt': ['SomeQueue', 'Arn'] } + ); expect(awsCompileSQSEvents.serverless.service .provider.compiledCloudFormationTemplate.Resources .FirstEventSourceMappingSQSForeignQueue.Properties.EventSourceArn ).to.deep.equal( { 'Fn::ImportValue': 'ForeignQueue' } ); + expect(awsCompileSQSEvents.serverless.service + .provider.compiledCloudFormationTemplate.Resources + .FirstEventSourceMappingSQSMyQueue.Properties.EventSourceArn + ).to.deep.equal( + { + 'Fn::Join': [ + ':', + [ + 'arn', + 'aws', + 'sqs', + { + Ref: 'AWS::Region', + }, + { + Ref: 'AWS::AccountId', + }, + 'MyQueue', + ], + ], + }); }); - it('fails if keys other than Fn::GetAtt/ImportValue are used for dynamic queue ARN', () => { + it('fails if keys other than Fn::GetAtt/ImportValue/Join are used for dynamic ARNs', () => { awsCompileSQSEvents.serverless.service.functions = { first: { events: [