Cloudformation: setting Availability Zone in target group creation

0

Hi, I’m working on creating a target group of type IP(for a NLB) that points to a private IP address located in a different VPC within the same AWS account. However, when writing the CloudFormation code, I’m encountering an issue.

Resource handler returned message: "The Availability Zone is required for IP address '10.33.0.12' because it is not in the VPC (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: 92f48469-8445-49aa-a8e8-07037esgfsdg)"

This issue occurs because, in CloudFormation, I'm unable to specify the Availability Zone for the IP address. Is there a way to resolve this, or is it a limitation of CloudFormation?

I tried this solution from the GUI Concole and I can do this. Enter image description here

my cloudformation code:

...
Type: AWS::ElasticLoadBalancingV2::TargetGroup
      Properties:
        HealthCheckEnabled: true
        HealthCheckPort: 8888
        HealthCheckProtocol: TCP
        Name: !Sub "${Project}-myMachineTG-tg"
        TargetType: ip
        Protocol: TCP
        Port: 8888
        VpcId:
          Fn::ImportValue:
            !Sub "${Project}igress"
        Targets:
        - Id: !Ref PrivateIp-vm
asked a month ago50 views
1 Answer
2
Accepted Answer

Hello.

How about setting "AvailabilityZone: all" as shown below?
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-targetgroup-targetdescription.html

TargetGroup1: 
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckEnabled: true
      HealthCheckIntervalSeconds: 30
      HealthCheckPort: traffic-port
      HealthCheckProtocol: TCP
      HealthyThresholdCount: 5
      IpAddressType: ipv4
      Name: !Sub ${SystemPrefix}-${Environment}-tg
      Port: 80
      Protocol: TCP
      TargetGroupAttributes: 
        - Key: preserve_client_ip.enabled
          Value: false
      Targets:
        - AvailabilityZone: all
          Id: !Ref TargetIP
          Port: 80
      TargetType: ip
      UnhealthyThresholdCount: 2
      VpcId: !Ref VPCID
profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions