This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
forked from davidgf/serverless-plugin-canary-deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad75ec5
commit cf5dca8
Showing
14 changed files
with
238 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
] | ||
} | ||
} | ||
}, | ||
{ | ||
"sns": "snsTopic" | ||
} | ||
], | ||
"deploymentSettings": { | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function replaceTopicSubscriptionFunctionWithAlias(snsTopic, functionAlias, functionName) { | ||
const subscriptions = snsTopic.Properties.Subscription; | ||
|
||
const isTargetSubscription = (subscription) => { | ||
const endpoint = subscription.Endpoint || {}; | ||
const funcDetails = (endpoint['Fn::GetAtt'] || []); | ||
const [funcName] = funcDetails; | ||
return funcName ? funcName === functionName : false; | ||
}; | ||
|
||
const restOfSubscriptions = subscriptions.filter(subscription => !isTargetSubscription(subscription)); | ||
const subscriptionWithAlias = { Endpoint: { Ref: functionAlias }, Protocol: 'lambda' }; | ||
const newSubscriptions = [...restOfSubscriptions, subscriptionWithAlias]; | ||
|
||
const newProperties = { ...snsTopic.Properties, Subscription: newSubscriptions }; | ||
return { ...snsTopic, Properties: newProperties }; | ||
} | ||
|
||
const Sns = { | ||
replaceTopicSubscriptionFunctionWithAlias | ||
}; | ||
|
||
module.exports = Sns; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { expect } = require('chai'); | ||
const Sns = require('./Sns'); | ||
|
||
describe('Sns', () => { | ||
describe('.replaceTopicSubscriptionFunctionWithAlias', () => { | ||
const functionName = 'HelloLambdaFunction'; | ||
const snsTopic = { | ||
Type: 'AWS::SNS::Topic', | ||
Properties: { | ||
TopicName: 'snsTopic', | ||
DisplayName: '', | ||
Subscription: [ | ||
{ | ||
Endpoint: { | ||
'Fn::GetAtt': [functionName, 'Arn'] | ||
}, | ||
Protocol: 'lambda' | ||
}, | ||
{ | ||
Endpoint: { | ||
'Fn::GetAtt': ['func', 'Arn'] | ||
}, | ||
Protocol: 'lambda' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
it("replaces the topic subscription's function for an alias", () => { | ||
const functionAlias = 'TheFunctionAlias'; | ||
const expected = { | ||
Type: 'AWS::SNS::Topic', | ||
Properties: { | ||
TopicName: 'snsTopic', | ||
DisplayName: '', | ||
Subscription: [ | ||
{ | ||
Endpoint: { | ||
'Fn::GetAtt': ['func', 'Arn'] | ||
}, | ||
Protocol: 'lambda' | ||
}, | ||
{ | ||
Endpoint: { Ref: functionAlias }, | ||
Protocol: 'lambda' | ||
} | ||
] | ||
} | ||
}; | ||
const actual = Sns.replaceTopicSubscriptionFunctionWithAlias(snsTopic, functionAlias, functionName); | ||
expect(actual).to.deep.equal(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.