0
votes

I'm trying to create an "AWS::ElasticLoadBalancingV2::TargetGroup" with a 'lambda' Target through my Cloudformation Template.

If I don't specify a port then I get an error that the field port is required

But if I do specify the port with target type "lambda" I get the error that the port should not be specified for target type lambda...

How can I automate through CFT or aws cli commands to create a targetgroup pointing to my lambdas ARN?

1

1 Answers

0
votes

So I would do the following using AWS cli. Creating target group;

create file called for example target-group.json with content;

{
    "Name": "nameOfTagretGroup",
    "TargetType": "lambda"
}

and then run aws elbv2 create-target-group --cli-input-json target-group.json. Or using aws cli only;

aws elbv2 create-target-group --name $targetName  --target-type lambda

Next create a file called for example register-lambda.json with content;

{
    "TargetGroupArn": "ARN_OF_CREATED_TARGET_GROUP",
    "Targets": [
        {
            "Id": "Lambda_ARN",
            "AvailabilityZone": "AZ_OF_YOUR_LAMBDA"
        }
    ]
}

and then run; aws elbv2 register-targets --cli-input-json register-lambda.json. Or using just using CLI input;

aws elbv2 register-targets --target-group-arn $target_arn --targets Id=$Lambda_ARN,AvailabilityZone=AZ_OF_YOUR_LAMBDA

I believe that should work for you and resolve your issues.