You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-57Lines changed: 56 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,20 +5,28 @@ Terraform module pattern to build a standard Lambda API.
5
5
6
6
#### [New to Terraform Modules at BYU?](https://github.com/byu-oit/terraform-documentation)
7
7
8
-
This module uses CodeDeploy to deploy a Lambda behind an ALB.
8
+
This module deploys a Lambda behind an ALB.
9
+
10
+
## CodeDeploy Option
11
+
12
+
Optionally, CodeDeploy can be used to perform "blue/green" deployments of new versions of the Lambda.
13
+
14
+
Before switching production traffic to the new Lambda, CodeDeploy runs Postman tests. This is done by:
9
15
10
-
Before switching production traffic to the new Lambda, CodeDeploy runs Postman tests.
11
-
This is done by:
12
16
* Having all production traffic (port `443`) sent to the Lambda version considered `live`
13
17
* Creating and deploying the new untested Lambda version to `$LATEST`
14
18
* Invoking a separate "test" Lambda that runs Postman tests
15
19
- These tests run against the port specified by `codedeploy_test_listener_port`, which corresponds to `$LATEST`
16
-
* If the tests pass, we give the alias `live` to the now-tested `$LATEST` version of the Lambda
20
+
* If the tests pass, we move the `live` alias to the now-tested `$LATEST` version of the Lambda
21
+
22
+
Note: If you do not specify `use_codedeploy = true`, the above process will not apply. Instead, the `live` alias will be updated directly by `terraform apply`.
23
+
24
+
Also Note: CodePipeline and CodeDeploy cannot be used together to deploy a Lambda. If you are using CodePipeline, you cannot specify `use_codedeploy = true`. CodeDeploy works fine with other pipelining tools (e.g. GitHub Actions).
##### TODO fix this section (copy pasta from standard fargate)
44
52
45
-
*ECS Cluster
46
-
* ECS Service
53
+
*Lambda Function
54
+
* with IAM role and policies
47
55
* with security group
48
-
* ECS Task Definition
49
-
* with IAM role
56
+
* with "live" alias (for blue-green deployment)
50
57
* CloudWatch Log Group
51
58
* ALB
52
59
* with security group
53
-
* 2 Target Groups (for blue-green deployment)
60
+
* with listeners and target groups
61
+
* 80 (redirects to 443)
62
+
* 443 (HTTPS forwards to "live")
63
+
* test_listener_port (HTTPS forwards to "latest")
54
64
* CodeDeploy App
55
65
* with IAM role
56
66
* CodeDeploy Group
57
67
* DNS A-Record
58
-
* AutoScaling Target
59
-
* AutoScaling Policies (one for stepping up and one for stepping down)
60
-
* CloudWatch Metric Alarms (one for stepping up and one for stepping down)
61
68
62
69
## Requirements
63
70
* Terraform version 0.12.21 or greater
@@ -110,13 +117,20 @@ This module will create a CloudWatch log group named `/aws/lambda/<app_name>-<en
110
117
For instance with the [above example](#usage) the logs could be found in the CloudWatch log group: `aws/lambda/my-lambda-dev`.
111
118
112
119
## Outputs
113
-
##### TODO fill out this section
114
120
115
121
| Name | Type | Description |
116
122
| --- | --- | --- |
123
+
| lambda |[object](https://www.terraform.io/docs/providers/aws/r/lambda_function.html#argument-reference)| The Lambda that handles API requests |
124
+
| lambda_security_group |[object](https://www.terraform.io/docs/providers/aws/r/security_group.html#argument-reference)| Controls what the Lambda can access |
125
+
| lambda_live_alias |[object](https://www.terraform.io/docs/providers/aws/r/lambda_alias.html#argument-reference)| Controls which version of the Lambda receives "live" traffic |
126
+
| codedeploy_deployment_group |[object](https://www.terraform.io/docs/providers/aws/r/codedeploy_deployment_group.html#argument-reference)| The CodeDeploy deployment group object. |
127
+
| codedeploy_appspec_json_file | string | Filename of the generated appspec.json file |
128
+
| alb |[object](https://www.terraform.io/docs/providers/aws/r/lb.html#argument-reference)| The Application Load Balancer (ALB) object |
129
+
| alb_security_group |[object](https://www.terraform.io/docs/providers/aws/r/security_group.html#argument-reference)| The ALB's security group object |
130
+
| dns_record |[object](https://www.terraform.io/docs/providers/aws/r/route53_record.html#argument-reference)| The DNS A-record mapped to the ALB |
131
+
| cloudwatch_log_group |[object](https://www.terraform.io/docs/providers/aws/r/cloudwatch_log_group.html#argument-reference)| The log group for the Lambda's logs |
117
132
118
133
#### appspec
119
-
##### TODO fix this section (copy pasta from standard fargate)
120
134
121
135
This module also creates a JSON file in the project directory: `appspec.json` used to initiate a CodeDeploy Deployment.
122
136
@@ -125,15 +139,14 @@ Here's an example appspec.json file this creates:
@@ -179,23 +179,22 @@ And example with [lifecycle hooks](#codedeploy_lifecycle_hooks):
179
179
```
180
180
181
181
## CodeDeploy Blue-Green Deployment
182
-
##### TODO fix this section (copy pasta from standard fargate)
183
182
184
-
This module creates a blue-green deployment process with CodeDeploy. If a `codedeploy_test_listener_port` is provided
185
-
this module will create an ALB listener that will allow public traffic from that port to the running lambda.
183
+
If `use_codedeploy = true` is specified, this module creates a blue-green deployment process with CodeDeploy. If a `codedeploy_test_listener_port` is provided this module will create an ALB listener that will allow public traffic from that port to the running lambda.
186
184
187
185
When a CodeDeploy deployment is initiated (either via a pipeline or manually) CodeDeploy will:
188
-
1. call lambda function defined for `BeforeInstall` hook
189
-
2. attempt to create a new set of tasks (called the replacement set) with the new task definition etc. in the unused ALB Target Group
190
-
3. call lambda function defined for `AfterInstall` hook
191
-
4. associate the test listener (if defined) to the new target group
192
-
5. call lambda function defined for `AfterAllowTestTraffic` hook
193
-
6. call lambda function defined for `BeforeAllowTraffic` hook
194
-
7. associate the production listener to the new target group
195
-
8. call lambda function defined for `AfterAllowTraffic` hook
196
-
9. wait for the `codedeploy_termination_wait_time` in minutes before destroying the original task set (this is useful if you need to manually rollback)
197
-
198
-
At any step (except step #1) the deployment can rollback (either manually or by the lambda functions in the lifecycle hooks or if there was an error trying to actually deploy)
186
+
1. call lambda function defined for `BeforeAllowTraffic` hook
187
+
2. associate the "live" alias "TargetVersion"
188
+
3. call lambda function defined for `AfterAllowTraffic` hook
189
+
190
+
At any step the deployment can rollback (either manually or by the lambda functions in the lifecycle hooks or if there was an error trying to actually deploy)
191
+
192
+
If manual rollback is needed after the deployment has completed, that can be done in the Lambda Console:
193
+
1. Select your Lambda Function.
194
+
2. Select a function alias (aka. "Qualifier")
195
+
3. Click the "Edit alias" button
196
+
4. Select the version you want to roll back to
197
+
5. Click "Save"
199
198
200
199
##### TODO add diagrams to explain the blue-green deployment process
0 commit comments