Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Fn::Join in SQS arn builder #5351

Merged
merged 3 commits into from Mar 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -34,6 +34,16 @@ functions:
- sqs: - sqs:
arn: arn:
Fn::ImportValue: MyExportedQueueArnId Fn::ImportValue: MyExportedQueueArnId
- sqs:
arn:
Fn::Join:
- ":"
- - arn
- aws
- sqs
- Ref: AWS::Region
- Ref: AWS::AccountId
- MyOtherQueue
``` ```


## Setting the BatchSize ## Setting the BatchSize
@@ -49,7 +49,8 @@ class AwsCompileSQSEvents {
// for dynamic arns (GetAtt/ImportValue) // for dynamic arns (GetAtt/ImportValue)
if (Object.keys(event.sqs.arn).length !== 1 if (Object.keys(event.sqs.arn).length !== 1
|| !(_.has(event.sqs.arn, 'Fn::ImportValue') || !(_.has(event.sqs.arn, 'Fn::ImportValue')
|| _.has(event.sqs.arn, 'Fn::GetAtt'))) { || _.has(event.sqs.arn, 'Fn::GetAtt')
|| _.has(event.sqs.arn, 'Fn::Join'))) {
const errorMessage = [ const errorMessage = [
`Bad dynamic ARN property on sqs event in function "${functionName}"`, `Bad dynamic ARN property on sqs event in function "${functionName}"`,
' If you use a dynamic "arn" (such as with Fn::GetAtt or Fn::ImportValue)', ' If you use a dynamic "arn" (such as with Fn::GetAtt or Fn::ImportValue)',
@@ -84,6 +85,9 @@ class AwsCompileSQSEvents {
return EventSourceArn['Fn::GetAtt'][0]; return EventSourceArn['Fn::GetAtt'][0];
} else if (EventSourceArn['Fn::ImportValue']) { } else if (EventSourceArn['Fn::ImportValue']) {
return 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(); return EventSourceArn.split(':').pop();
}()); }());
@@ -391,18 +391,29 @@ describe('AwsCompileSQSEvents', () => {
arn: { 'Fn::ImportValue': 'ForeignQueue' }, arn: { 'Fn::ImportValue': 'ForeignQueue' },
}, },
}, },
{
sqs: {
arn: {
'Fn::Join': [
':', [
'arn', 'aws', 'sqs', {
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'MyQueue',
],
],
},
},
},
], ],
}, },
}; };


awsCompileSQSEvents.compileSQSEvents(); awsCompileSQSEvents.compileSQSEvents();


expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSSomeQueue.Properties.EventSourceArn
).to.deep.equal(
{ 'Fn::GetAtt': ['SomeQueue', 'Arn'] }
);
expect(awsCompileSQSEvents.serverless.service expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution .provider.compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution
.Properties.Policies[0].PolicyDocument.Statement[0] .Properties.Policies[0].PolicyDocument.Statement[0]
@@ -424,18 +435,62 @@ describe('AwsCompileSQSEvents', () => {
{ {
'Fn::ImportValue': 'ForeignQueue', '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 expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources .provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSForeignQueue.Properties.EventSourceArn .FirstEventSourceMappingSQSForeignQueue.Properties.EventSourceArn
).to.deep.equal( ).to.deep.equal(
{ 'Fn::ImportValue': 'ForeignQueue' } { '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 = { awsCompileSQSEvents.serverless.service.functions = {
first: { first: {
events: [ events: [
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.