UNPKG

serverless-blue-green-deployments

Version:

A Serverless plugin to implement blue/green deployment of Lambda functions

794 lines 20.2 kB
{ "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" } } ] } } }, "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": [ "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/1564330164016-2019-07-28T16:09:24.016Z/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" ] }, "HelloLambdaVersionRHVG2n1cRVoFYJ0kJnUAcBVJReLL6daOns7anjY9fM": { "Type": "AWS::Lambda::Version", "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "HelloLambdaFunction" }, "CodeSha256": "PoTfIarmnTRnh2Y8EVEfsVov/mws9YuZE1wIJSvX9C0=" } }, "PreHookLambdaFunction": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Ref": "ServerlessDeploymentBucket" }, "S3Key": "serverless/canary-deployments-test/dev/1564330164016-2019-07-28T16:09:24.016Z/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" ] }, "PreHookLambdaVersionYMLJvXbFsSqDzpnfBWUQfh7A4ectwPI90Y5x0W8jUeQ": { "Type": "AWS::Lambda::Version", "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "PreHookLambdaFunction" }, "CodeSha256": "PoTfIarmnTRnh2Y8EVEfsVov/mws9YuZE1wIJSvX9C0=" } }, "PostHookLambdaFunction": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": { "Ref": "ServerlessDeploymentBucket" }, "S3Key": "serverless/canary-deployments-test/dev/1564330164016-2019-07-28T16:09:24.016Z/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" ] }, "PostHookLambdaVersionv7HMbsQ3AxhkXTwFUBayTIYZS3SXT8h1Rs64KBg6Sk": { "Type": "AWS::Lambda::Version", "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "PostHookLambdaFunction" }, "CodeSha256": "PoTfIarmnTRnh2Y8EVEfsVov/mws9YuZE1wIJSvX9C0=" } }, "HelloEventsRuleSchedule1": { "Type": "AWS::Events::Rule", "Properties": { "ScheduleExpression": "rate(1 minute)", "State": "DISABLED", "Targets": [ { "Arn": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "Id": "helloSchedule" } ] } }, "HelloLambdaPermissionEventsRuleSchedule1": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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:", { "Ref": "AWS::Partition" }, ":apigateway:", { "Ref": "AWS::Region" }, ":lambda:path/2015-03-31/functions/", { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "/invocations" ] ] } }, "MethodResponses": [] } }, "ApiGatewayDeployment1564330154194": { "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ApiGatewayRestApi" }, "StageName": "dev" }, "DependsOn": [ "ApiGatewayMethodHelloGet" ] }, "HelloLambdaPermissionApiGateway": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Join": [ "", [ "arn:", { "Ref": "AWS::Partition" }, ":execute-api:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":", { "Ref": "ApiGatewayRestApi" }, "/*/*" ] ] } } }, "SNSTopicSnsTopic": { "Type": "AWS::SNS::Topic", "Properties": { "TopicName": "snsTopic", "DisplayName": "", "Subscription": [ { "Endpoint": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "Protocol": "lambda" } ] } }, "HelloLambdaPermissionSnsTopicSNS": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "Protocol": "lambda", "TopicArn": { "Ref": "SNSTopicFooTopic" }, "FilterPolicy": { "eventType": [ "FooEvent" ] } } }, "HelloLambdaPermissionFooTopicSNS": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "StartingPosition": "TRIM_HORIZON", "Enabled": "True" } }, "HelloIotTopicRule1": { "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { "RuleDisabled": "false", "Sql": "SELECT * FROM 'some_topic'", "Actions": [ { "Lambda": { "FunctionArn": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] } } } ] } } }, "HelloLambdaPermissionIotTopicRule1": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] } } }, "HelloLambdaPermissionLogsSubscriptionFilterCloudWatchLog": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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": { "Fn::GetAtt": [ "HelloLambdaFunction", "Arn" ] }, "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" } }, "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": "HelloLambdaVersionRHVG2n1cRVoFYJ0kJnUAcBVJReLL6daOns7anjY9fM" } }, "PreHookLambdaFunctionQualifiedArn": { "Description": "Current Lambda function version", "Value": { "Ref": "PreHookLambdaVersionYMLJvXbFsSqDzpnfBWUQfh7A4ectwPI90Y5x0W8jUeQ" } }, "PostHookLambdaFunctionQualifiedArn": { "Description": "Current Lambda function version", "Value": { "Ref": "PostHookLambdaVersionv7HMbsQ3AxhkXTwFUBayTIYZS3SXT8h1Rs64KBg6Sk" } }, "ServiceEndpoint": { "Description": "URL of the service endpoint", "Value": { "Fn::Join": [ "", [ "https://", { "Ref": "ApiGatewayRestApi" }, ".execute-api.", { "Ref": "AWS::Region" }, ".", { "Ref": "AWS::URLSuffix" }, "/dev" ] ] } } } }