Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda docker image #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lambda/autoscale/autoscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def update_record(zone_id, ip, hostname, operation):
'ResourceRecordSet': {
'Name': hostname,
'Type': 'A',
'TTL': os.environ['ROUTE53_TTL'],
'TTL': int(os.environ['ROUTE53_TTL']),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Ensure ROUTE53_TTL is always set in the environment variables to avoid potential KeyError

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a try-except block to handle potential ValueError when converting ROUTE53_TTL to int

'ResourceRecords': [{'Value': ip}]
}
}
Expand Down
11 changes: 7 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ data "aws_iam_policy_document" "lifecycle_policy" {
}

data "archive_file" "autoscale" {
count = var.lambda_image_uri != null ? 0 : 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a descriptive comment explaining the purpose of this count parameter

type = "zip"
source_file = "${path.module}/lambda/autoscale/autoscale.py"
output_path = "${path.module}/lambda/dist/autoscale.zip"
Expand All @@ -106,12 +107,14 @@ data "archive_file" "autoscale" {
resource "aws_lambda_function" "autoscale_handling" {
depends_on = [aws_sns_topic.autoscale_handling]

filename = data.archive_file.autoscale.output_path
filename = var.lambda_image_uri != null ? null : data.archive_file.autoscale[0].output_path
function_name = "${var.vpc_name}-${var.autoscale_handler_unique_identifier}"
role = aws_iam_role.autoscale_handling.arn
handler = "autoscale.lambda_handler"
runtime = "python3.8"
source_code_hash = filebase64sha256(data.archive_file.autoscale.output_path)
handler = var.lambda_image_uri != null ? null : "autoscale.lambda_handler"
runtime = var.lambda_image_uri != null ? null : "python3.8"
source_code_hash = var.lambda_image_uri != null ? null : filebase64sha256(data.archive_file.autoscale[0].output_path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Ensure that source_code_hash is properly set when using a Docker image to trigger updates

image_uri = var.lambda_image_uri != null ? var.lambda_image_uri : null
package_type = var.lambda_image_uri != null ? "Image" : "Zip"
Comment on lines +110 to +117
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: These conditional expressions may impact readability. Consider using separate resources for Image and Zip package types

description = "Handles DNS for autoscaling groups by receiving autoscaling notifications and setting/deleting records from route53"
environment {
variables = {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ variable "route53_record_ttl" {
default = 300
type = number
}

variable "lambda_image_uri" {
default = null
type = string
description = "The URI of the Lambda image"
}
Comment on lines +28 to +32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Add a note in the description about when to use this variable, e.g., 'Provide this URI to use a custom Lambda image instead of the default Python code'