Skip to content

Commit 7f89c4b

Browse files
committed
feat: added docker support, closes #21
and added domain url, closes #15
1 parent a20665d commit 7f89c4b

File tree

10 files changed

+347
-245
lines changed

10 files changed

+347
-245
lines changed

README.md

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,26 @@ Also Note: CodePipeline and CodeDeploy cannot be used together to deploy a Lambd
2626
## Usage
2727
```hcl
2828
module "lambda_api" {
29-
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v1.3.0"
30-
app_name = "my-lambda"
31-
env = "dev"
32-
codedeploy_service_role_arn = module.acs.power_builder_role.arn
33-
lambda_zip_file = "./src/lambda.zip"
34-
handler = "index.handler"
35-
runtime = "nodejs12.x"
29+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
30+
app_name = "my-lambda-dev"
31+
env = "dev"
32+
zip_file = {
33+
filename = "./src/lambda.zip"
34+
handler = "index.handler"
35+
runtime = "nodejs12.x"
36+
}
3637
hosted_zone = module.acs.route53_zone
3738
https_certificate_arn = module.acs.certificate.arn
3839
vpc_id = module.acs.vpc.id
3940
public_subnet_ids = module.acs.public_subnet_ids
4041
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
41-
codedeploy_test_listener_port = 4443
42-
use_codedeploy = true
43-
timeout = 3
44-
memory_size = 128
45-
46-
lambda_vpc_config = {
47-
subnet_ids = module.acs.private_subnet_ids
48-
security_group_ids = ["sg-3asdfadsfasdfas"]
49-
}
50-
51-
codedeploy_lifecycle_hooks = {
52-
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
53-
AfterAllowTraffic = null
42+
codedeploy_config = {
43+
service_role_arn = module.acs.power_builder_role.arn
44+
test_listener_port = 4443
45+
lifecycle_hooks = {
46+
BeforeAllowTraffic = aws_lambda_function.test_lambda.function_name
47+
AfterAllowTraffic = null
48+
}
5449
}
5550
}
5651
```
@@ -79,29 +74,30 @@ module "lambda_api" {
7974
## Inputs
8075
| Name | Type | Description | Default |
8176
| --- | --- | --- | --- |
82-
| app_name | string | application name |
83-
| env | string | application environment (e.g. dev, stg, prd) |
84-
| codedeploy_service_role_arn | string | ARN of the IAM Role for the CodeDeploy to use to initiate new deployments. (usually the PowerBuilder Role) |
85-
| lambda_zip_file | string | File that contains your compiled or zipped source code. |
86-
| handler | string | Lambda event handler |
87-
| runtime | string | Lambda runtime |
88-
| lambda_vpc_config | [object](#lambda_vpc_config) | Lambda VPC object. Used if lambda requires to run inside a VPC | null
89-
| environment_variables | map(string) | A map that defines environment variables for the Lambda function. |
90-
| hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone. |
91-
| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain. |
92-
| codedeploy_lifecycle_hooks | [object](#codedeploy_lifecycle_hooks) | Define Lambda Functions for CodeDeploy lifecycle event hooks. Or set this variable to null to not have any lifecycle hooks invoked. Defaults to null | null
93-
| appspec_filename | string | Filename (including path) to use when outputing appspec json. | `appspec.json` in the current working directory (i.e. where you ran `terraform apply`) |
94-
| codedeploy_test_listener_port | number | The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set. Defaults to null | null
95-
| vpc_id | string | VPC ID to deploy ALB and Lambda (If specified). |
96-
| public_subnet_ids | list(string) | List of subnet IDs for the ALB. |
97-
| tags | map(string) | A map of AWS Tags to attach to each resource created | {}
98-
| role_permissions_boundary_arn | string | IAM Role Permissions Boundary ARN |
99-
| log_retention_in_days | number | CloudWatch log group retention in days. Defaults to 7. | 7
100-
| lambda_policies | list(string) | List of IAM Policy ARNs to attach to the lambda role. | []'
101-
| use_codedeploy | bool | If true, CodeDeploy App and Deployment Group will be created and TF will not update alias to point to new versions of the Lambda (becuase CodeDeploy will do that). | false
102-
| timeout | number | How long the lambda will run (in seconds) before timing out | 3 (same as terraform default)
103-
| memory_size | number | Size of the memory of the lambda. CPU will scale along with it | 128 (same as terraform default)
104-
| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Lambda API. | false
77+
| app_name | string | application name (include the env aka. 'my-api-dev') | |
78+
| zip_file | [object](#zip_file_config) | configuration for a zip file lambda (conflicts with `image_uri`) | null |
79+
| image_uri | string | ECR Image URI containing the function's deployment package (conflicts with `zip_file`)| null |
80+
| lambda_vpc_config | [object](#lambda_vpc_config) | Lambda VPC object. Used if lambda requires to run inside a VPC | null |
81+
| environment_variables | map(string) | A map that defines environment variables for the Lambda function. | |
82+
| domain_url | string | Custom domain URL for the API, defaults to <app_name>.<hosted_zone_domain> | null | |
83+
| hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone. | |
84+
| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain. | |
85+
| codedeploy_config | [object](#codedeploy_config) | Configuration for putting CodeDeploy on the lambda | null |
86+
| vpc_id | string | VPC ID to deploy ALB and Lambda (If specified). | |
87+
| public_subnet_ids | list(string) | List of subnet IDs for the ALB. | |
88+
| tags | map(string) | A map of AWS Tags to attach to each resource created | {} |
89+
| role_permissions_boundary_arn | string | IAM Role Permissions Boundary ARN | |
90+
| log_retention_in_days | number | CloudWatch log group retention in days. Defaults to 7. | 7 |
91+
| lambda_policies | list(string) | List of IAM Policy ARNs to attach to the lambda role. | []' |
92+
| timeout | number | How long the lambda will run (in seconds) before timing out | 3 (same as terraform default) |
93+
| memory_size | number | Size of the memory of the lambda. CPU will scale along with it | 128 (same as terraform default) |
94+
| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Lambda API. | false |
95+
96+
#### zip_file_config
97+
This configuration is used for when you are including the zipped up code for the lambda instead of using the `image_uri`
98+
* `filename` - (string) File that contains your compiled or zipped source code
99+
* `handler` - (string) Lambda event handler
100+
* `runtime` - (string) Lambda runtime
105101

106102
#### lambda_vpc_config
107103

@@ -110,6 +106,13 @@ This variable is used when the lambda needs to be run from within a VPC.
110106
* **`subnet_ids`** - List of subnet IDs for the Lambda service.
111107
* **`security_group_ids`** - List of extra security group IDs to attach to the lambda.
112108

109+
#### codedeploy_config
110+
If this configuration is included then this module will add the CodeDeploy App and Group required to deploy new versions of the Lambda through CodeDeploy, also allowing for the use of the LifeCycle hooks.
111+
* `service_role_arn` - (string) ARN of the IAM Role for the CodeDeploy to use to initiate new deployments (usually the PowerBuilder Role)
112+
* `lifecycle_hooks` - ([object](#codedeploy_lifecycle_hooks)) | Define Lambda Functions for CodeDeploy lifecycle event hooks. Or set this variable to null to not have any lifecycle hooks invoked
113+
* `appspec_filename` - (string) Filename (including path) to use when outputing appspec json (defaults to `appspec.json` in the current working directory)
114+
* `test_listener_port` - (number) The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set
115+
113116
#### codedeploy_lifecycle_hooks
114117

115118
This variable is used when generating the [appspec.json](#appspec) file. This will define what Lambda Functions to invoke
@@ -128,7 +131,7 @@ You can pass in either the object from the AWS terraform provider for an AWS Hos
128131

129132
#### CloudWatch logs
130133

131-
This module will create a CloudWatch log group named `/aws/lambda/<app_name>-<env>`.
134+
This module will create a CloudWatch log group named `/aws/lambda/<app_name>`.
132135

133136
For instance with the [above example](#usage) the logs could be found in the CloudWatch log group: `aws/lambda/my-lambda-dev`.
134137

examples/ci-12/ci.tf

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ provider "aws" {
88
}
99

1010
module "acs" {
11-
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v2.1.0"
11+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
1212
}
1313

14-
module "lambda_api" {
15-
source = "../../"
16-
app_name = "my-lambda"
17-
env = "dev"
18-
lambda_zip_file = "./lambda.zip"
19-
handler = "index.handler"
20-
runtime = "nodejs12.x"
14+
module "lambda_zip_api" {
15+
source = "../../"
16+
app_name = "my-lambda"
17+
zip_file = {
18+
filename = "./lambda.zip"
19+
handler = "index.handler"
20+
runtime = "nodejs12.x"
21+
}
2122
hosted_zone = module.acs.route53_zone
2223
https_certificate_arn = module.acs.certificate.arn
2324
vpc_id = module.acs.vpc.id
@@ -31,38 +32,19 @@ module "lambda_api" {
3132
}
3233
}
3334

34-
output "lambda" {
35-
value = module.lambda_api.lambda
36-
}
37-
38-
output "lambda_security_group" {
39-
value = module.lambda_api.lambda_security_group
40-
}
41-
42-
output "lambda_live_alias" {
43-
value = module.lambda_api.lambda_live_alias
44-
}
45-
46-
output "codedeploy_deployment_group" {
47-
value = module.lambda_api.codedeploy_deployment_group
48-
}
49-
50-
output "codedeploy_appspec_json_file" {
51-
value = module.lambda_api.codedeploy_appspec_json_file
52-
}
53-
54-
output "alb" {
55-
value = module.lambda_api.alb
56-
}
57-
58-
output "alb_security_group" {
59-
value = module.lambda_api.alb_security_group
60-
}
61-
62-
output "dns_record" {
63-
value = module.lambda_api.dns_record
64-
}
35+
module "lambda_docker_api" {
36+
source = "../../"
37+
app_name = "my-docker-lambda"
38+
image_uri = "crccheck/hello-world:latest"
39+
hosted_zone = module.acs.route53_zone
40+
https_certificate_arn = module.acs.certificate.arn
41+
vpc_id = module.acs.vpc.id
42+
public_subnet_ids = module.acs.public_subnet_ids
43+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
44+
xray_enabled = true
6545

66-
output "cloudwatch_log_group" {
67-
value = module.lambda_api.cloudwatch_log_group
46+
lambda_vpc_config = {
47+
subnet_ids = module.acs.private_subnet_ids
48+
security_group_ids = []
49+
}
6850
}

examples/ci-13/ci.tf

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ provider "aws" {
88
}
99

1010
module "acs" {
11-
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.1.0"
11+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
1212
}
1313

1414
module "lambda_api" {
15-
source = "../../"
16-
app_name = "my-lambda"
17-
env = "dev"
18-
lambda_zip_file = "./lambda.zip"
19-
handler = "index.handler"
20-
runtime = "nodejs12.x"
15+
source = "../../"
16+
app_name = "my-lambda"
17+
zip_file = {
18+
filename = "./lambda.zip"
19+
handler = "index.handler"
20+
runtime = "nodejs12.x"
21+
}
2122
hosted_zone = module.acs.route53_zone
2223
https_certificate_arn = module.acs.certificate.arn
2324
vpc_id = module.acs.vpc.id
@@ -31,38 +32,19 @@ module "lambda_api" {
3132
}
3233
}
3334

34-
output "lambda" {
35-
value = module.lambda_api.lambda
36-
}
37-
38-
output "lambda_security_group" {
39-
value = module.lambda_api.lambda_security_group
40-
}
41-
42-
output "lambda_live_alias" {
43-
value = module.lambda_api.lambda_live_alias
44-
}
45-
46-
output "codedeploy_deployment_group" {
47-
value = module.lambda_api.codedeploy_deployment_group
48-
}
49-
50-
output "codedeploy_appspec_json_file" {
51-
value = module.lambda_api.codedeploy_appspec_json_file
52-
}
53-
54-
output "alb" {
55-
value = module.lambda_api.alb
56-
}
57-
58-
output "alb_security_group" {
59-
value = module.lambda_api.alb_security_group
60-
}
61-
62-
output "dns_record" {
63-
value = module.lambda_api.dns_record
64-
}
35+
module "lambda_docker_api" {
36+
source = "../../"
37+
app_name = "my-docker-lambda"
38+
image_uri = "crccheck/hello-world:latest"
39+
hosted_zone = module.acs.route53_zone
40+
https_certificate_arn = module.acs.certificate.arn
41+
vpc_id = module.acs.vpc.id
42+
public_subnet_ids = module.acs.public_subnet_ids
43+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
44+
xray_enabled = true
6545

66-
output "cloudwatch_log_group" {
67-
value = module.lambda_api.cloudwatch_log_group
46+
lambda_vpc_config = {
47+
subnet_ids = module.acs.private_subnet_ids
48+
security_group_ids = []
49+
}
6850
}

examples/docker-lambda/docker.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
terraform {
2+
required_version = "0.13.4"
3+
}
4+
5+
provider "aws" {
6+
version = "~> 3.0"
7+
region = "us-west-2"
8+
}
9+
10+
module "acs" {
11+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
12+
}
13+
14+
module "lambda_api" {
15+
source = "../../"
16+
app_name = "my-docker-lambda"
17+
image = "my-image-from-my-ecr:latest"
18+
hosted_zone = module.acs.route53_zone
19+
https_certificate_arn = module.acs.certificate.arn
20+
vpc_id = module.acs.vpc.id
21+
public_subnet_ids = module.acs.public_subnet_ids
22+
role_permissions_boundary_arn = module.acs.role_permissions_boundary.arn
23+
xray_enabled = true
24+
25+
lambda_vpc_config = {
26+
subnet_ids = module.acs.private_subnet_ids
27+
security_group_ids = []
28+
}
29+
}
30+
31+
output "lambda" {
32+
value = module.lambda_api.lambda
33+
}
34+
35+
output "lambda_security_group" {
36+
value = module.lambda_api.lambda_security_group
37+
}
38+
39+
output "lambda_live_alias" {
40+
value = module.lambda_api.lambda_live_alias
41+
}
42+
43+
output "codedeploy_deployment_group" {
44+
value = module.lambda_api.codedeploy_deployment_group
45+
}
46+
47+
output "codedeploy_appspec_json_file" {
48+
value = module.lambda_api.codedeploy_appspec_json_file
49+
}
50+
51+
output "alb" {
52+
value = module.lambda_api.alb
53+
}
54+
55+
output "alb_security_group" {
56+
value = module.lambda_api.alb_security_group
57+
}
58+
59+
output "dns_record" {
60+
value = module.lambda_api.dns_record
61+
}
62+
63+
output "cloudwatch_log_group" {
64+
value = module.lambda_api.cloudwatch_log_group
65+
}

examples/no-codedeploy/example.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ provider "aws" {
44
}
55

66
module "acs" {
7-
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.2.0"
7+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
88
}
99

1010
module "lambda_api" {
11-
// source = "../../"
12-
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v1.3.0"
13-
app_name = "my-lambda"
14-
env = "dev"
15-
lambda_zip_file = "./src/lambda.zip"
16-
handler = "index.handler"
17-
runtime = "nodejs12.x"
11+
source = "../../"
12+
# source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v1.3.0"
13+
app_name = "my-lambda-dev"
14+
zip_file = {
15+
filename = "./src/lambda.zip"
16+
handler = "index.handler"
17+
runtime = "nodejs12.x"
18+
}
1819
hosted_zone = module.acs.route53_zone
1920
https_certificate_arn = module.acs.certificate.arn
2021
vpc_id = module.acs.vpc.id

examples/simple-lambda-in-vpc/example.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ provider "aws" {
44
}
55

66
module "acs" {
7-
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v2.1.0"
7+
source = "github.com/byu-oit/terraform-aws-acs-info?ref=v3.4.0"
88
}
99

1010
module "lambda_api" {
1111
# source = "../../"
12-
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v1.3.0"
13-
app_name = "my-lambda"
14-
env = "dev"
15-
lambda_zip_file = "./src/lambda.zip"
16-
handler = "index.handler"
17-
runtime = "nodejs12.x"
12+
source = "github.com/byu-oit/terraform-aws-lambda-api?ref=v2.0.0"
13+
app_name = "my-lambda-dev"
14+
zip_file = {
15+
filename = "./src/lambda.zip"
16+
handler = "index.handler"
17+
runtime = "nodejs12.x"
18+
}
1819
hosted_zone = module.acs.route53_zone
1920
https_certificate_arn = module.acs.certificate.arn
2021
vpc_id = module.acs.vpc.id

0 commit comments

Comments
 (0)