Skip to content

Commit

Permalink
Merge pull request davidgf#41 from operasoftware/fix-split-stacks
Browse files Browse the repository at this point in the history
Switch from Fn::Sub to Fn::Join in CF templates
  • Loading branch information
davidgf committed Dec 5, 2018
2 parents 2950ab8 + 4d4a6d6 commit 54f028d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
15 changes: 14 additions & 1 deletion fixtures/1.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,20 @@
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Ref": "HelloLambdaFunctionAliasLive"
},
"/invocations"
]
]
}
},
"MethodResponses": []
Expand Down
15 changes: 14 additions & 1 deletion fixtures/2.output.without-hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,20 @@
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Ref": "HelloLambdaFunctionAliasLive"
},
"/invocations"
]
]
}
},
"MethodResponses": []
Expand Down
15 changes: 14 additions & 1 deletion fixtures/3.output.with-existing-codedeploy-role.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,20 @@
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Ref": "HelloLambdaFunctionAliasLive"
},
"/invocations"
]
]
}
},
"MethodResponses": []
Expand Down
12 changes: 7 additions & 5 deletions lib/CfTemplateGenerators/ApiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const _ = require('lodash/fp');

function buildUriForAlias(functionAlias) {
const aliasArn = [
'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${',
functionAlias,
'}/invocations'
].join('');
return { 'Fn::Sub': aliasArn };
'arn:aws:apigateway:',
{ 'Ref': 'AWS::Region' },
':lambda:path/2015-03-31/functions/',
{ 'Ref': functionAlias },
'/invocations'
];
return { 'Fn::Join': [ '', aliasArn ] };
}

function replaceMethodUriWithAlias(apiGatewayMethod, functionAlias) {
Expand Down
12 changes: 7 additions & 5 deletions lib/CfTemplateGenerators/ApiGateway.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ describe('ApiGateway', () => {
it('replaces the method URI with a function alias ARN', () => {
const functionAlias = 'TheFunctionAlias';
const uriWithAwsVariables = [
'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${',
functionAlias,
'}/invocations'
].join('');
const uri = { 'Fn::Sub': uriWithAwsVariables };
'arn:aws:apigateway:',
{ Ref: 'AWS::Region' },
':lambda:path/2015-03-31/functions/',
{ Ref: functionAlias },
'/invocations'
];
const uri = { 'Fn::Join': [ '', uriWithAwsVariables ] };
const expected = _.set('Properties.Integration.Uri', uri, apiGatewayMethod);
const actual = ApiGateway.replaceMethodUriWithAlias(apiGatewayMethod, functionAlias);
expect(actual).to.deep.equal(expected);
Expand Down

0 comments on commit 54f028d

Please sign in to comment.