Skip to content

Commit 54f028d

Browse files
authored
Merge pull request #41 from operasoftware/fix-split-stacks
Switch from Fn::Sub to Fn::Join in CF templates
2 parents 2950ab8 + 4d4a6d6 commit 54f028d

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

fixtures/1.output.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,20 @@
286286
"IntegrationHttpMethod": "POST",
287287
"Type": "AWS_PROXY",
288288
"Uri": {
289-
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
289+
"Fn::Join": [
290+
"",
291+
[
292+
"arn:aws:apigateway:",
293+
{
294+
"Ref": "AWS::Region"
295+
},
296+
":lambda:path/2015-03-31/functions/",
297+
{
298+
"Ref": "HelloLambdaFunctionAliasLive"
299+
},
300+
"/invocations"
301+
]
302+
]
290303
}
291304
},
292305
"MethodResponses": []

fixtures/2.output.without-hooks.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,20 @@
190190
"IntegrationHttpMethod": "POST",
191191
"Type": "AWS_PROXY",
192192
"Uri": {
193-
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
193+
"Fn::Join": [
194+
"",
195+
[
196+
"arn:aws:apigateway:",
197+
{
198+
"Ref": "AWS::Region"
199+
},
200+
":lambda:path/2015-03-31/functions/",
201+
{
202+
"Ref": "HelloLambdaFunctionAliasLive"
203+
},
204+
"/invocations"
205+
]
206+
]
194207
}
195208
},
196209
"MethodResponses": []

fixtures/3.output.with-existing-codedeploy-role.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,20 @@
286286
"IntegrationHttpMethod": "POST",
287287
"Type": "AWS_PROXY",
288288
"Uri": {
289-
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloLambdaFunctionAliasLive}/invocations"
289+
"Fn::Join": [
290+
"",
291+
[
292+
"arn:aws:apigateway:",
293+
{
294+
"Ref": "AWS::Region"
295+
},
296+
":lambda:path/2015-03-31/functions/",
297+
{
298+
"Ref": "HelloLambdaFunctionAliasLive"
299+
},
300+
"/invocations"
301+
]
302+
]
290303
}
291304
},
292305
"MethodResponses": []

lib/CfTemplateGenerators/ApiGateway.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ const _ = require('lodash/fp');
22

33
function buildUriForAlias(functionAlias) {
44
const aliasArn = [
5-
'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${',
6-
functionAlias,
7-
'}/invocations'
8-
].join('');
9-
return { 'Fn::Sub': aliasArn };
5+
'arn:aws:apigateway:',
6+
{ 'Ref': 'AWS::Region' },
7+
':lambda:path/2015-03-31/functions/',
8+
{ 'Ref': functionAlias },
9+
'/invocations'
10+
];
11+
return { 'Fn::Join': [ '', aliasArn ] };
1012
}
1113

1214
function replaceMethodUriWithAlias(apiGatewayMethod, functionAlias) {

lib/CfTemplateGenerators/ApiGateway.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ describe('ApiGateway', () => {
3333
it('replaces the method URI with a function alias ARN', () => {
3434
const functionAlias = 'TheFunctionAlias';
3535
const uriWithAwsVariables = [
36-
'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${',
37-
functionAlias,
38-
'}/invocations'
39-
].join('');
40-
const uri = { 'Fn::Sub': uriWithAwsVariables };
36+
'arn:aws:apigateway:',
37+
{ Ref: 'AWS::Region' },
38+
':lambda:path/2015-03-31/functions/',
39+
{ Ref: functionAlias },
40+
'/invocations'
41+
];
42+
const uri = { 'Fn::Join': [ '', uriWithAwsVariables ] };
4143
const expected = _.set('Properties.Integration.Uri', uri, apiGatewayMethod);
4244
const actual = ApiGateway.replaceMethodUriWithAlias(apiGatewayMethod, functionAlias);
4345
expect(actual).to.deep.equal(expected);

0 commit comments

Comments
 (0)