Skip to content

Commit 79f7933

Browse files
committed
started docs. tried to get appspec correct. fixed alias version number.
1 parent abf7628 commit 79f7933

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ This is done by:
2626
## Inputs
2727
| Name | Type | Description | Default |
2828
| --- | --- | --- | --- |
29+
| app_name | string | | |
30+
| codedeploy_service_role_arn | string | | |
31+
| lambda_src_dir | string | | |
32+
| hosted_zone | object | | |
2933

3034
## Outputs
3135
| Name | Type | Description |

examples/my-lambda/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ exports.handler = async function (event, context) {
2626
}
2727
*/
2828

29+
console.log(event)
30+
console.log(context)
31+
2932
return {
3033
'isBase64Encoded': false,
3134
'statusCode': 200,

main.tf

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ locals {
111111
AfterAllowTraffic = null
112112
}
113113
]) : null
114+
115+
# Hacky workaround for bootstrap issue
116+
# is_initial = aws_lambda_alias.initial.function_version == aws_lambda_alias.live.function_version
114117
}
115118

116119

@@ -317,9 +320,10 @@ resource "aws_lambda_function" "api_lambda" {
317320

318321
resource "aws_lambda_alias" "live" {
319322
name = "live"
320-
description = "a sample description"
323+
description = "a sample description" //TODO:
321324
function_name = aws_lambda_function.api_lambda.arn
322-
function_version = "1"
325+
# Get the version of the lambda when it is first created
326+
function_version = aws_lambda_function.api_lambda.version
323327
# Let CodeDeploy handle changes to the function version that this alias refers to
324328
lifecycle {
325329
ignore_changes = [
@@ -328,6 +332,20 @@ resource "aws_lambda_alias" "live" {
328332
}
329333
}
330334

335+
# resource "aws_lambda_alias" "initial" {
336+
# name = "initial"
337+
# description = "a sample description" //TODO:
338+
# function_name = aws_lambda_function.api_lambda.arn
339+
# # Get the version of the lambda when it is first created
340+
# function_version = aws_lambda_function.api_lambda.version
341+
# # Let CodeDeploy handle changes to the function version that this alias refers to
342+
# lifecycle {
343+
# ignore_changes = [
344+
# function_version
345+
# ]
346+
# }
347+
# }
348+
331349
# ==================== CodeDeploy ====================
332350

333351
resource "aws_codedeploy_app" "app" {
@@ -382,10 +400,11 @@ resource "aws_iam_role_policy_attachment" "lambda_cloudwatch_attach" {
382400

383401
# ==================== AppSpec file ====================
384402

385-
data "aws_lambda_alias" "alias_for_old_version" {
386-
function_name = aws_lambda_function.api_lambda.function_name
387-
name = "live" //TODO: Make local?
388-
}
403+
# data "aws_lambda_alias" "alias_for_old_version" {
404+
# count = local.is_initial ? 0 : 1
405+
# function_name = aws_lambda_function.api_lambda.function_name
406+
# name = "live" //TODO: Make local?
407+
# }
389408

390409
resource "local_file" "appspec_json" {
391410
filename = "${path.cwd}/appspec.json"
@@ -397,7 +416,7 @@ resource "local_file" "appspec_json" {
397416
Properties = {
398417
Name = aws_lambda_function.api_lambda.function_name
399418
Alias = aws_lambda_alias.live.name
400-
CurrentVersion = data.aws_lambda_alias.alias_for_old_version.function_version
419+
# CurrentVersion = local.is_initial ? aws_lambda_alias.initial.function_version : data.aws_lambda_alias.alias_for_old_version[0].function_version
401420
TargetVersion = aws_lambda_function.api_lambda.version
402421
}
403422
}

0 commit comments

Comments
 (0)