Skip to content

Commit 6d976cc

Browse files
committed
variables for handler and runtime. fix lambda name. add outputs.
1 parent 416d7bf commit 6d976cc

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

examples/simple-lambda-with-deploy-test/example.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module "lambda_api" {
1313
env = "dev"
1414
codedeploy_service_role_arn = module.acs.power_builder_role.arn
1515
lambda_src_dir = "./src"
16+
handler = "index.handler"
17+
runtime = "nodejs12.x"
1618
hosted_zone = module.acs.route53_zone
1719
https_certificate_arn = module.acs.certificate.arn
1820
vpc_id = module.acs.vpc.id

main.tf

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ locals {
2828
# is_initial = aws_lambda_alias.initial.function_version == aws_lambda_alias.live.function_version
2929
}
3030

31-
3231
# ==================== ALB ====================
3332

3433
resource "aws_alb" "alb" {
@@ -248,10 +247,10 @@ resource "aws_security_group" "lambda_sg" {
248247
resource "aws_lambda_function" "api_lambda" {
249248
filename = data.archive_file.cleanup_lambda_zip.output_path
250249
source_code_hash = data.archive_file.cleanup_lambda_zip.output_base64sha256
251-
function_name = "my-lambda"
250+
function_name = local.long_name
252251
role = aws_iam_role.iam_for_lambda.arn
253-
handler = "index.handler"
254-
runtime = "nodejs12.x"
252+
handler = var.handler
253+
runtime = var.runtime
255254
publish = true
256255

257256
vpc_config {
@@ -268,7 +267,7 @@ resource "aws_lambda_function" "api_lambda" {
268267

269268
resource "aws_lambda_alias" "live" {
270269
name = "live"
271-
description = "a sample description" //TODO:
270+
description = "ALB sends traffic to this version"
272271
function_name = aws_lambda_function.api_lambda.arn
273272
# Get the version of the lambda when it is first created
274273
function_version = aws_lambda_function.api_lambda.version
@@ -280,42 +279,13 @@ resource "aws_lambda_alias" "live" {
280279
}
281280
}
282281

283-
# resource "aws_lambda_alias" "initial" {
284-
# name = "initial"
285-
# description = "a sample description" //TODO:
286-
# function_name = aws_lambda_function.api_lambda.arn
287-
# # Get the version of the lambda when it is first created
288-
# function_version = aws_lambda_function.api_lambda.version
289-
# # Let CodeDeploy handle changes to the function version that this alias refers to
290-
# lifecycle {
291-
# ignore_changes = [
292-
# function_version
293-
# ]
294-
# }
295-
# }
296-
297282
# ==================== CodeDeploy ====================
298283

299284
resource "aws_codedeploy_app" "app" {
300285
compute_platform = "Lambda"
301286
name = "${local.long_name}-cd"
302287
}
303288

304-
# resource "aws_codedeploy_deployment_config" "config" {
305-
# deployment_config_name = "${local.long_name}-cfg"
306-
# compute_platform = "Lambda"
307-
308-
# //TODO: There are other ways to configure this
309-
# traffic_routing_config {
310-
# type = "TimeBasedLinear"
311-
312-
# time_based_linear {
313-
# interval = 10
314-
# percentage = 10
315-
# }
316-
# }
317-
# }
318-
319289
resource "aws_codedeploy_deployment_group" "deployment_group" {
320290
app_name = aws_codedeploy_app.app.name
321291
deployment_group_name = "${local.long_name}-dg"
@@ -332,7 +302,6 @@ resource "aws_codedeploy_deployment_group" "deployment_group" {
332302
}
333303
}
334304

335-
336305
# ==================== CloudWatch ====================
337306

338307
resource "aws_cloudwatch_log_group" "log_group" {

outputs.tf

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
# output "appspec" {
2-
# value = local_file.appspec_json.content
3-
# }
1+
output "lambda" {
2+
value = aws_lambda_function.api_lambda
3+
}
4+
5+
output "lambda_security_group" {
6+
value = aws_security_group.lambda_sg
7+
}
8+
9+
output "lambda_live_alias" {
10+
value = aws_lambda_alias.live
11+
}
12+
13+
output "codedeploy_deployment_group" {
14+
value = aws_codedeploy_deployment_group.deployment_group
15+
}
16+
17+
output "codedeploy_appspec_json_file" {
18+
value = local_file.appspec_json.filename
19+
}
20+
21+
output "alb" {
22+
value = aws_alb.alb
23+
}
24+
25+
output "alb_security_group" {
26+
value = aws_security_group.alb-sg
27+
}
428

529
output "dns_record" {
630
value = aws_route53_record.a_record
731
}
32+
33+
output "cloudwatch_log_group" {
34+
value = aws_cloudwatch_log_group.log_group
35+
}

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ variable "lambda_src_dir" {
1818
description = "Directory that contains your lambda source code"
1919
}
2020

21+
variable "handler" {
22+
type = string
23+
description = "Lambda event handler"
24+
}
25+
26+
variable "runtime" {
27+
type = string
28+
description = "Lambda runtime"
29+
}
30+
2131
variable "hosted_zone" {
2232
type = object({
2333
name = string,

0 commit comments

Comments
 (0)