Skip to content

Terraform with Lambda function to automatically maintain NLB target group registrations for Aurora cluster instances based on their role (reader/writer).

Notifications You must be signed in to change notification settings

shipmonk-rnd/terraform-aws-adjust-target-group

Repository files navigation

Adjust target group based on the RDS Aurora Endpoints

This Lambda function automatically maintains ALB target group registrations for Aurora cluster instances based on their role (reader/writer).

Functionality

  • Dynamically updates ALB target groups with Aurora instance IP addresses
  • Supports separate reader and writer endpoint management
  • Excludes auto-scaled instances from target registration
  • Handles target group registration/deregistration automatically

Environment variables used in the Lambda function

  • AURORA_CLUSTER_ID: Aurora cluster identifier
  • TARGET_GROUP_ARN: ALB target group ARN to manage
  • TARGET_PORT: Database port (default: 3306)
  • TYPE: Target type - 'reader' or 'writer' (default: 'reader')

Use Case

Good for NLB used for AWS VPC Endpoints.

Before you do anything in this module

Install pre-commit hooks by running following commands:

brew install pre-commit terraform-docs
pre-commit install

Requirements

No requirements.

Providers

Name Version
archive n/a
aws n/a

Modules

No modules.

Resources

Name Type
aws_cloudwatch_event_rule.every_minute resource
aws_cloudwatch_event_target.lambda_target resource
aws_iam_role.lambda_execution_role resource
aws_iam_role_policy.lambda_policy resource
aws_lambda_function.aurora_nlb resource
aws_lambda_permission.allow_cloudwatch_to_call_lambda resource
aws_security_group.lambda_sg resource
archive_file.lambda_zip data source
aws_iam_policy_document.lambda_assume_role_policy data source
aws_iam_policy_document.lambda_policy data source

Inputs

Name Description Type Default Required
identifier ID of the Aurora cluster to fetch IP addresses from, or instance identifier for IDS instance string n/a yes
name Prefixing name for the Lambda function and associated resources string n/a yes
target_group_arn ARN of the target group to update with Aurora endpoints IP addresses string n/a yes
target_port Port on which the target group is listening string n/a yes
type Type of the target group, either 'reader' or 'writer' string n/a yes
vpc_id VPC ID for Lambda security group string n/a yes
vpc_subnet_ids Subnet IDs for Lambda to run within the VPC list(string) n/a yes

Outputs

Name Description
function_name n/a

About

Terraform with Lambda function to automatically maintain NLB target group registrations for Aurora cluster instances based on their role (reader/writer).

Resources

Stars

Watchers

Forks

Packages

No packages published