Skip to content

AWS Lambda which registers IP addresses to the LB Target Group based on DNS record

License

Notifications You must be signed in to change notification settings

dex4er/lambda-lb-target-group-dns

Repository files navigation

lambda-lb-target-group-dns

GitHub Snapshot Release Trunk Check Docker Image Version Amazon ECR Image Version

AWS Lambda which registers IP addresses to the LB Target Group based on DNS record.

Usage

Copy the container to your private ECR and use it as the container image or copy ZIP distribution and use it with an Amazon Linux 2023 runtime.

Lambda accepts parameters:

{
  "targetGroupArn": "arn:aws:elasticloadbalancing:REGION:ACCOUNTID:targetgroup/TARGETGROUP/NNN",
  "domainName": "XXX.gr7.REGION.eks.amazonaws.com",
  "targetPort": 0
}

Lambda returns the status:

{
  "status": "OK"
}

You can test it as a standalone tool as:

lambda-lb-target-group-dns -target-group-arn XXX -domain-name XXX -target-port NNN

Container image

Copy the container to your private ECR:

From DockerHub:

docker pull dex4er/lambda-lb-target-group-dns:TAG
docker tag dex4er/lambda-lb-target-group-dns:TAG ACCOUNTID.dkr.ecr.REGION.amazonaws.com/dex4er/lambda-lb-target-group-dns:TAG
docker push ACCOUNTID.dkr.ecr.REGION.amazonaws.com/dex4er/lambda-lb-target-group-dns:TAG

or from Amazon ECR Public:

docker pull public.ecr.aws/dex4er/lambda-lb-target-group-dns:TAG
docker tag public.ecr.aws/dex4er/lambda-lb-target-group-dns:TAG ACCOUNTID.dkr.ecr.REGION.amazonaws.com/dex4er/lambda-lb-target-group-dns:TAG
docker push ACCOUNTID.dkr.ecr.REGION.amazonaws.com/dex4er/lambda-lb-target-group-dns:TAG

Supported tags:

  • vX.Y.Z-linux-amd64
  • vX.Y.Z-linux-arm64
  • vX.Y.Z
  • vX.Y
  • vX
  • latest

IAM

This lambda function needs the following permissions:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "elasticloadbalancing:DescribeTargetGroups",
        "elasticloadbalancing:DescribeTargetHealth"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "elasticloadbalancing:DeregisterTargets",
        "elasticloadbalancing:RegisterTargets"
      ],
      "Resource": "arn:aws:elasticloadbalancing:REGION:ACCOUNTID:targetgroup/NAME/NNN"
    }
  ]
}

Example

See example/terraform directory for an example how to use this lambda function.

License

The MIT License (MIT)

Copyright (c) 2024 Piotr Roszatycki [email protected]

About

AWS Lambda which registers IP addresses to the LB Target Group based on DNS record

Resources

License

Stars

Watchers

Forks

Packages

No packages published