Skip to content

Commit 9f4f654

Browse files
committed
refactor: using Fn::Sub around SQS
1 parent e139f1a commit 9f4f654

File tree

2 files changed

+28
-68
lines changed

2 files changed

+28
-68
lines changed

lib/package/sqs/compileMethodsToSqs.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,16 @@ module.exports = {
4747
},
4848

4949
getSqsMethodIntegration(http) {
50-
let queueName = http.queueName
51-
if (typeof http.queueName == 'string') {
52-
queueName = `"${queueName}"`
53-
}
5450
const integration = {
5551
IntegrationHttpMethod: 'POST',
5652
Type: 'AWS',
5753
Credentials: {
5854
'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn']
5955
},
6056
Uri: {
61-
'Fn::Join': [
62-
'',
63-
[
64-
'arn:aws:apigateway:',
65-
{
66-
Ref: 'AWS::Region'
67-
},
68-
':sqs:path//',
69-
{
70-
Ref: 'AWS::AccountId'
71-
},
72-
'/',
73-
queueName
74-
]
57+
'Fn::Sub': [
58+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
59+
{ queueName: http.queueName }
7560
]
7661
},
7762
RequestParameters: _.merge(

lib/package/sqs/compileMethodsToSqs.test.js

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,11 @@ describe('#compileMethodsToSqs()', () => {
6767
Type: 'AWS',
6868
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
6969
Uri: {
70-
'Fn::Join': [
71-
'',
72-
[
73-
'arn:aws:apigateway:',
74-
{ Ref: 'AWS::Region' },
75-
':sqs:path//',
76-
{ Ref: 'AWS::AccountId' },
77-
'/',
78-
'"myQueue"'
79-
]
70+
'Fn::Sub': [
71+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
72+
{
73+
queueName: 'myQueue'
74+
}
8075
]
8176
},
8277
RequestParameters: {
@@ -171,16 +166,11 @@ describe('#compileMethodsToSqs()', () => {
171166
Type: 'AWS',
172167
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
173168
Uri: {
174-
'Fn::Join': [
175-
'',
176-
[
177-
'arn:aws:apigateway:',
178-
{ Ref: 'AWS::Region' },
179-
':sqs:path//',
180-
{ Ref: 'AWS::AccountId' },
181-
'/',
182-
'"myQueue"'
183-
]
169+
'Fn::Sub': [
170+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
171+
{
172+
queueName: 'myQueue'
173+
}
184174
]
185175
},
186176
RequestParameters: {
@@ -274,16 +264,11 @@ describe('#compileMethodsToSqs()', () => {
274264
Type: 'AWS',
275265
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
276266
Uri: {
277-
'Fn::Join': [
278-
'',
279-
[
280-
'arn:aws:apigateway:',
281-
{ Ref: 'AWS::Region' },
282-
':sqs:path//',
283-
{ Ref: 'AWS::AccountId' },
284-
'/',
285-
'"myQueue"'
286-
]
267+
'Fn::Sub': [
268+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
269+
{
270+
queueName: 'myQueue'
271+
}
287272
]
288273
},
289274
RequestParameters: {
@@ -365,16 +350,11 @@ describe('#compileMethodsToSqs()', () => {
365350
Type: 'AWS',
366351
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
367352
Uri: {
368-
'Fn::Join': [
369-
'',
370-
[
371-
'arn:aws:apigateway:',
372-
{ Ref: 'AWS::Region' },
373-
':sqs:path//',
374-
{ Ref: 'AWS::AccountId' },
375-
'/',
376-
'"myQueue"'
377-
]
353+
'Fn::Sub': [
354+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
355+
{
356+
queueName: 'myQueue'
357+
}
378358
]
379359
},
380360
RequestParameters: {
@@ -456,16 +436,11 @@ describe('#compileMethodsToSqs()', () => {
456436
Type: 'AWS',
457437
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
458438
Uri: {
459-
'Fn::Join': [
460-
'',
461-
[
462-
'arn:aws:apigateway:',
463-
{ Ref: 'AWS::Region' },
464-
':sqs:path//',
465-
{ Ref: 'AWS::AccountId' },
466-
'/',
467-
'"myQueue"'
468-
]
439+
'Fn::Sub': [
440+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
441+
{
442+
queueName: 'myQueue'
443+
}
469444
]
470445
},
471446
RequestParameters: {

0 commit comments

Comments
 (0)