serverless-blue-green-deployments
Version:
A Serverless plugin to implement blue/green deployment of Lambda functions
1,021 lines (1,020 loc) • 26.2 kB
JSON
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "The AWS CloudFormation template for this Serverless application",
"Resources": {
"ServerlessDeploymentBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}
}
},
"ServerlessDeploymentBucketPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:*",
"Effect": "Deny",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "ServerlessDeploymentBucket"
},
"/*"
]
]
}
],
"Condition": {
"Bool": {
"aws:SecureTransport": false
}
}
}
]
}
}
},
"HelloLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-hello"
}
},
"PreHookLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-preHook"
}
},
"PostHookLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-postHook"
}
},
"IamRoleLambdaExecution": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Policies": [
{
"PolicyName": {
"Fn::Join": [
"-",
[
"dev",
"canary-deployments-test",
"lambda"
]
]
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream"
],
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev*:*"
}
]
},
{
"Effect": "Allow",
"Action": [
"logs:PutLogEvents"
],
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev*:*:*"
}
]
},
{
"Effect": "Allow",
"Action": [
"codedeploy:*"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"execute-api:ManageConnections"
],
"Resource": [
"arn:aws:execute-api:*:*:*/@connections/*"
]
},
{
"Effect": "Allow",
"Action": [
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:DescribeStream",
"dynamodb:ListStreams"
],
"Resource": [
{
"Fn::GetAtt": [
"StreamsTestTable",
"StreamArn"
]
}
]
},
{
"Effect": "Allow",
"Action": [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes"
],
"Resource": [
{
"Fn::GetAtt": [
"MyQueue",
"Arn"
]
}
]
}
]
}
}
],
"Path": "/",
"RoleName": {
"Fn::Join": [
"-",
[
"canary-deployments-test",
"dev",
{
"Ref": "AWS::Region"
},
"lambdaRole"
]
]
}
}
},
"HelloLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/canary-deployments-test/dev/1574869358544-2019-11-27T15:42:38.544Z/canary-deployments-test.zip"
},
"FunctionName": "canary-deployments-test-dev-hello",
"Handler": "handler.hello",
"MemorySize": 1024,
"Role": {
"Fn::GetAtt": [
"IamRoleLambdaExecution",
"Arn"
]
},
"Runtime": "nodejs10.x",
"Timeout": 6
},
"DependsOn": [
"HelloLogGroup",
"IamRoleLambdaExecution"
]
},
"HelloLambdaVersiongLPmTeISPdmIrw0XEdq7lLCeAODS6C3K7zQ3Cvt8": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "HelloLambdaFunction"
},
"CodeSha256": "gRcEfRD1nNOkLQkVUzd/JRHnHRoUly17PqOom8inXFs="
}
},
"PreHookLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/canary-deployments-test/dev/1574869358544-2019-11-27T15:42:38.544Z/canary-deployments-test.zip"
},
"FunctionName": "canary-deployments-test-dev-preHook",
"Handler": "hooks.pre",
"MemorySize": 1024,
"Role": {
"Fn::GetAtt": [
"IamRoleLambdaExecution",
"Arn"
]
},
"Runtime": "nodejs10.x",
"Timeout": 6
},
"DependsOn": [
"PreHookLogGroup",
"IamRoleLambdaExecution"
]
},
"PreHookLambdaVersionQFH4V7PdOWiXrYcHacSmKZkFmbMA4BqP9kzptqlaws": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "PreHookLambdaFunction"
},
"CodeSha256": "gRcEfRD1nNOkLQkVUzd/JRHnHRoUly17PqOom8inXFs="
}
},
"PostHookLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/canary-deployments-test/dev/1574869358544-2019-11-27T15:42:38.544Z/canary-deployments-test.zip"
},
"FunctionName": "canary-deployments-test-dev-postHook",
"Handler": "hooks.post",
"MemorySize": 1024,
"Role": {
"Fn::GetAtt": [
"IamRoleLambdaExecution",
"Arn"
]
},
"Runtime": "nodejs10.x",
"Timeout": 6
},
"DependsOn": [
"PostHookLogGroup",
"IamRoleLambdaExecution"
]
},
"PostHookLambdaVersionnSlT36U73RqRsdZBEPN8CWBWYwJaU3gEAD1bTjPGNc": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "PostHookLambdaFunction"
},
"CodeSha256": "gRcEfRD1nNOkLQkVUzd/JRHnHRoUly17PqOom8inXFs="
}
},
"HelloEventsRuleSchedule1": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State": "DISABLED",
"Targets": [
{
"Arn": {
"Ref": "LiveAlias"
},
"Id": "helloSchedule"
}
]
}
},
"HelloLambdaPermissionEventsRuleSchedule1": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"HelloEventsRuleSchedule1",
"Arn"
]
}
}
},
"ApiGatewayRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "dev-canary-deployments-test",
"EndpointConfiguration": {
"Types": [
"EDGE"
]
}
}
},
"ApiGatewayResourceHello": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"ParentId": {
"Fn::GetAtt": [
"ApiGatewayRestApi",
"RootResourceId"
]
},
"PathPart": "hello",
"RestApiId": {
"Ref": "ApiGatewayRestApi"
}
}
},
"ApiGatewayMethodHelloGet": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"RequestParameters": {},
"ResourceId": {
"Ref": "ApiGatewayResourceHello"
},
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"ApiKeyRequired": false,
"AuthorizationType": "NONE",
"Integration": {
"IntegrationHttpMethod": "POST",
"Type": "AWS_PROXY",
"Uri": {
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Ref": "LiveAlias"
},
"/invocations"
]
]
}
},
"MethodResponses": []
}
},
"ApiGatewayDeployment1574869309726": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"StageName": "dev"
},
"DependsOn": [
"ApiGatewayMethodHelloGet"
]
},
"HelloLambdaPermissionApiGateway": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":execute-api:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":",
{
"Ref": "ApiGatewayRestApi"
},
"/*/*"
]
]
}
}
},
"WebsocketsApi": {
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"Name": "dev-canary-deployments-test-websockets",
"RouteSelectionExpression": "$request.body.action",
"Description": "Serverless Websockets",
"ProtocolType": "WEBSOCKET"
}
},
"HelloWebsocketsIntegration": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
"Ref": "WebsocketsApi"
},
"IntegrationType": "AWS_PROXY",
"IntegrationUri": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Ref": "LiveAlias"
},
"/invocations"
]
]
}
}
},
"HelloLambdaPermissionWebsockets": {
"Type": "AWS::Lambda::Permission",
"DependsOn": [
"WebsocketsApi",
"HelloLambdaFunction"
],
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "apigateway.amazonaws.com"
}
},
"SdefaultWebsocketsRoute": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "WebsocketsApi"
},
"RouteKey": "$default",
"AuthorizationType": "NONE",
"Target": {
"Fn::Join": [
"/",
[
"integrations",
{
"Ref": "HelloWebsocketsIntegration"
}
]
]
}
}
},
"WebsocketsDeployment1574869309726": {
"Type": "AWS::ApiGatewayV2::Deployment",
"DependsOn": [
"SdefaultWebsocketsRoute"
],
"Properties": {
"ApiId": {
"Ref": "WebsocketsApi"
},
"Description": "Serverless Websockets"
}
},
"WebsocketsDeploymentStage": {
"Type": "AWS::ApiGatewayV2::Stage",
"Properties": {
"ApiId": {
"Ref": "WebsocketsApi"
},
"DeploymentId": {
"Ref": "WebsocketsDeployment1574869309726"
},
"StageName": "dev",
"Description": "Serverless Websockets"
}
},
"SNSTopicSnsTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"TopicName": "snsTopic",
"DisplayName": "",
"Subscription": [
{
"Endpoint": {
"Ref": "LiveAlias"
},
"Protocol": "lambda"
}
]
}
},
"HelloLambdaPermissionSnsTopicSNS": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "sns.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":sns:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":",
"snsTopic"
]
]
}
}
},
"SNSTopicFooTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"TopicName": "fooTopic",
"DisplayName": "fooTopic"
}
},
"HelloSnsSubscriptionFooTopic": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Endpoint": {
"Ref": "LiveAlias"
},
"Protocol": "lambda",
"TopicArn": {
"Ref": "SNSTopicFooTopic"
},
"FilterPolicy": {
"eventType": [
"FooEvent"
]
}
}
},
"HelloLambdaPermissionFooTopicSNS": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "sns.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":sns:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":",
"fooTopic"
]
]
}
}
},
"HelloEventSourceMappingDynamodbStreamsTestTable": {
"Type": "AWS::Lambda::EventSourceMapping",
"DependsOn": "IamRoleLambdaExecution",
"Properties": {
"BatchSize": 10,
"EventSourceArn": {
"Fn::GetAtt": [
"StreamsTestTable",
"StreamArn"
]
},
"FunctionName": {
"Ref": "LiveAlias"
},
"StartingPosition": "TRIM_HORIZON",
"Enabled": "True"
}
},
"HelloIotTopicRule1": {
"Type": "AWS::IoT::TopicRule",
"Properties": {
"TopicRulePayload": {
"RuleDisabled": "false",
"Sql": "SELECT * FROM 'some_topic'",
"Actions": [
{
"Lambda": {
"FunctionArn": {
"Ref": "LiveAlias"
}
}
}
]
}
}
},
"HelloLambdaPermissionIotTopicRule1": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "iot.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iot:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":rule/",
{
"Ref": "HelloIotTopicRule1"
}
]
]
}
}
},
"HelloLogsSubscriptionFilterCloudWatchLog1": {
"Type": "AWS::Logs::SubscriptionFilter",
"DependsOn": "HelloLambdaPermissionLogsSubscriptionFilterCloudWatchLog",
"Properties": {
"LogGroupName": "/aws/lambda/sls-wshop-dev-hello",
"FilterPattern": "",
"DestinationArn": {
"Ref": "LiveAlias"
}
}
},
"HelloLambdaPermissionLogsSubscriptionFilterCloudWatchLog": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LiveAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": {
"Fn::Join": [
"",
[
"logs.",
{
"Ref": "AWS::Region"
},
".amazonaws.com"
]
]
},
"SourceArn": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":logs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":log-group:",
"/aws/lambda/sls-wshop-dev-hello",
":*"
]
]
}
}
},
"HelloEventSourceMappingSQSMyQueue": {
"Type": "AWS::Lambda::EventSourceMapping",
"DependsOn": "IamRoleLambdaExecution",
"Properties": {
"BatchSize": 10,
"EventSourceArn": {
"Fn::GetAtt": [
"MyQueue",
"Arn"
]
},
"FunctionName": {
"Ref": "LiveAlias"
},
"Enabled": "True"
}
},
"HelloFooAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"Namespace": "AWS/Lambda",
"MetricName": "Errors",
"Threshold": 1,
"Period": 60,
"EvaluationPeriods": 1,
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"OKActions": [],
"AlarmActions": [],
"InsufficientDataActions": [],
"Dimensions": [
{
"Name": "FunctionName",
"Value": {
"Ref": "HelloLambdaFunction"
}
}
],
"TreatMissingData": "missing",
"Statistic": "Minimum"
}
},
"BluegreendeploymentstestdevDeploymentApplication": {
"Type": "AWS::CodeDeploy::Application",
"Properties": {
"ComputePlatform": "Lambda"
}
},
"CodeDeployServiceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda",
"arn:aws:iam::aws:policy/AWSLambda_FullAccess"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"codedeploy.amazonaws.com"
]
}
}
]
}
}
},
"HelloLambdaFunctionDeploymentGroup": {
"Type": "AWS::CodeDeploy::DeploymentGroup",
"Properties": {
"ApplicationName": {
"Ref": "BluegreendeploymentstestdevDeploymentApplication"
},
"AutoRollbackConfiguration": {
"Enabled": true,
"Events": [
"DEPLOYMENT_FAILURE",
"DEPLOYMENT_STOP_ON_ALARM",
"DEPLOYMENT_STOP_ON_REQUEST"
]
},
"DeploymentConfigName": {
"Fn::Sub": [
"CodeDeployDefault.Lambda${ConfigName}",
{
"ConfigName": "Linear10PercentEvery1Minute"
}
]
},
"DeploymentStyle": {
"DeploymentType": "BLUE_GREEN",
"DeploymentOption": "WITH_TRAFFIC_CONTROL"
},
"ServiceRoleArn": {
"Fn::GetAtt": [
"CodeDeployServiceRole",
"Arn"
]
},
"AlarmConfiguration": {
"Alarms": [
{
"Name": {
"Ref": "HelloFooAlarm"
}
}
],
"Enabled": true
}
}
},
"LiveAlias": {
"Type": "AWS::Lambda::Alias",
"Properties": {
"FunctionVersion": {
"Fn::GetAtt": [
"HelloLambdaVersiongLPmTeISPdmIrw0XEdq7lLCeAODS6C3K7zQ3Cvt8",
"Version"
]
},
"FunctionName": {
"Ref": "HelloLambdaFunction"
},
"Name": "Live"
},
"UpdatePolicy": {
"CodeDeployLambdaAliasUpdate": {
"ApplicationName": {
"Ref": "BluegreendeploymentstestdevDeploymentApplication"
},
"AfterAllowTrafficHook": {
"Ref": "PostHookLambdaFunction"
},
"BeforeAllowTrafficHook": {
"Ref": "PreHookLambdaFunction"
},
"DeploymentGroupName": {
"Ref": "HelloLambdaFunctionDeploymentGroup"
}
}
}
},
"StreamsTestTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "StreamsTestTable",
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"StreamSpecification": {
"StreamViewType": "NEW_AND_OLD_IMAGES"
}
}
},
"MyQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"DelaySeconds": 0,
"VisibilityTimeout": 120
}
}
},
"Outputs": {
"ServerlessDeploymentBucketName": {
"Value": {
"Ref": "ServerlessDeploymentBucket"
}
},
"HelloLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "HelloLambdaVersiongLPmTeISPdmIrw0XEdq7lLCeAODS6C3K7zQ3Cvt8"
}
},
"PreHookLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "PreHookLambdaVersionQFH4V7PdOWiXrYcHacSmKZkFmbMA4BqP9kzptqlaws"
}
},
"PostHookLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "PostHookLambdaVersionnSlT36U73RqRsdZBEPN8CWBWYwJaU3gEAD1bTjPGNc"
}
},
"ServiceEndpoint": {
"Description": "URL of the service endpoint",
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "ApiGatewayRestApi"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/dev"
]
]
}
},
"ServiceEndpointWebsocket": {
"Description": "URL of the service endpoint",
"Value": {
"Fn::Join": [
"",
[
"wss://",
{
"Ref": "WebsocketsApi"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/dev"
]
]
}
}
}
}