Skip to content

Instantly share code, notes, and snippets.

@klausbadelt
klausbadelt / cloudformation.yaml
Created October 8, 2018 07:08
The complete CloudFormation template
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
@klausbadelt
klausbadelt / cloudformation_snstopic.yaml
Created October 8, 2018 06:38
CloudFormation template - SNS topic
DevNotifyTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: Filmhub
DevNotifyKlausSMS:
Type: AWS::SNS::Subscription
Properties:
TopicArn: !Ref DevNotifyTopic
Protocol: sms
Endpoint: "1310*******" # enter your cell phone
@klausbadelt
klausbadelt / cloudformation_policy_rule.yaml
Last active October 8, 2018 06:27
CloudFormation template excerpt - Lambda policy and CloudWatch event rule
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
@klausbadelt
klausbadelt / cloudformation_parameters.yaml
Last active October 8, 2018 06:28
CloudFormation template excerpt - parameters
Parameters:
DeployBranch:
Description: A git push to this branch will trigger CD with CodePipeline.
Type: String
@klausbadelt
klausbadelt / cloudformation_lambda_function.yaml
Last active October 8, 2018 06:27
CloudFormation template excerpt - lambda function
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))
@klausbadelt
klausbadelt / index.js
Last active October 8, 2018 05:54
Clean CodePipeline notifications with CloudWatch Events and AWS Lambda
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}`
}