-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcanary-deployment.yaml
75 lines (71 loc) · 2.56 KB
/
canary-deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
This template creates the lambda functions, Step Functions, and CloudWatch Events Streams
required to trigger and execute the switch from one ECS service to another. It also creates
the blue ECS service - so upon completion the trigger should fire and the canary switch should start.
Parameters:
SetupStackName:
Type: String
Default: "canary-setup"
TemplateBucket:
Type: String
Default: "nbrand-code"
Resources:
handleECSEvents:
Type: 'AWS::Serverless::Function'
DependsOn: StepFunction
Properties:
Handler: index.lambda_handler
Runtime: python2.7
CodeUri: # CodeUri: 's3://my-code-bucket/my-function.zip'
Bucket: #!Ref TemplateBucket
Fn::ImportValue:
!Sub "${SetupStackName}-Bucket"
Key: lambdafunctions/handleECSEvents.zip
Description: Handles ECS Events even if there are duplicates or timing issues
Environment:
Variables:
TRIGGER_CONTAINERS: 'green-app'
STEP_FUNCTION: !GetAtt StepFunction.Outputs.StepArn
MemorySize: 128
Timeout: 3
Policies:
- "AWSLambdaFullAccess"
- "AWSStepFunctionsFullAccess"
Events:
ECSStream:
Description: "Sending ECS events to a Lambda function for processing"
Type: CloudWatchEvent
Properties:
Pattern:
source:
- 'aws.ecs'
detail-type:
- 'ECS Task State Change'
detail:
lastStatus:
- 'RUNNING'
desiredStatus:
- 'RUNNING'
Service:
Type: AWS::CloudFormation::Stack
DependsOn: handleECSEvents # Make sure that lambda function is ready
DependsOn: handleECSEventsECSStream # Make sure that the Event Stream is ready first
Properties:
TemplateURL: !Sub https://s3.amazonaws.com/${TemplateBucket}/templates/greenService.yaml
Parameters:
Cluster:
Fn::ImportValue:
!Sub "${SetupStackName}-Cluster" #!GetAtt Cluster.Outputs.ClusterName
TargetGroup:
Fn::ImportValue:
!Sub "${SetupStackName}-TG" #!GetAtt LoadBalancer.Outputs.TargetGroup
StepFunction:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub https://s3.amazonaws.com/${TemplateBucket}/templates/stepfunction.yaml
Parameters:
TemplateBucket:
Fn::ImportValue:
!Sub "${SetupStackName}-Bucket"