Created
October 8, 2018 07:08
-
-
Save klausbadelt/9e004c0eef87de697d689cc566637686 to your computer and use it in GitHub Desktop.
The complete CloudFormation template
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
AWSTemplateFormatVersion: '2010-09-09' | |
Parameters: | |
DeployBranch: | |
Description: A git push to this branch will trigger CD with CodePipeline. | |
Type: String | |
Resources: | |
WebPipelineNotifyFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
Code: | |
ZipFile: | | |
var SNS = require('aws-sdk/clients/sns') | |
var sns = new SNS() | |
exports.handler = async (event) => { | |
console.log(JSON.stringify(event)) | |
const params = { | |
Message: `Deploy of ${process.env.BRANCH} ${event.detail.state}`, | |
TopicArn: process.env.TOPIC_ARN, | |
Subject: `Deploy ${event.detail.state}` | |
} | |
console.log(JSON.stringify(params)) | |
return await sns.publish(params).promise() | |
} | |
Description: Notifies of deploys with SMS and email | |
Environment: | |
Variables: | |
TOPIC_ARN: !Ref DevNotifyTopic | |
BRANCH: !Ref DeployBranch | |
Handler: index.handler | |
Role: !GetAtt LambdaServiceRole.Arn | |
Runtime: nodejs8.10 | |
Timeout: 10 | |
WebPipelineNotifyPolicy: | |
Type: AWS::Lambda::Permission | |
Properties: | |
Action: lambda:InvokeFunction | |
FunctionName: !GetAtt WebPipelineNotifyFunction.Arn | |
Principal: events.amazonaws.com | |
SourceArn: !GetAtt WebPipelineNotifyRule.Arn | |
WebPipelineNotifyRule: | |
Type: AWS::Events::Rule | |
Properties: | |
Description: Triggers notification on pipeline state changes ie deploys | |
EventPattern: | |
detail-type: | |
- CodePipeline Pipeline Execution State Change | |
source: | |
- aws.codepipeline | |
State: ENABLED | |
Targets: | |
- Arn: !GetAtt WebPipelineNotifyFunction.Arn | |
Id: WebPipelineNotifyFunction | |
DevNotifyTopic: | |
Type: AWS::SNS::Topic | |
Properties: | |
DisplayName: Filmhub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment