NLB is not able to return Security Group ID

0

I am trying to create NLB using cloudformation template and I want security group to be return. I am following this documentation but its giving error. Documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html

I have attached file for reference.

Error: Template format error: Every Value member must be a string.. Rollback requested by user.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "The template used to create an ALB Service.",
  "Parameters": {
    "SecurityGroupIDs": {
      "Type": "CommaDelimitedList",
      "Default": "sg-00cdd0ae543d7d743c"
    },
    "SubnetIDs": {
      "Type": "CommaDelimitedList",
      "Default": "subnet-07bcbafea8d1ae10fe,subnet-07839cd50992c3c05b"
    },
    "VpcID": {
      "Type": "String",
      "Default": "vpc-096ae9d52761a14542"
    },
    "LoadBalancerName": {
      "Type": "String",
      "Default": "ajt-nlb"
    },
    "ArnAlb": {
      "Type": "String",
      "Default": "arn:aws:elasticloadbalancing:us-west-2:account:loadbalancer/app/cv-ann-ALB/9fd999dfa42663a4a"
    },
    "TargetGroupName": {
      "Type": "String",
      "Default": "ajt-tg"
    }
  },
  "Resources": {
    "TargetGroup": {
      "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
      "Properties": {
        "HealthCheckPath": "/healthcheck",
        "Name": {
          "Ref": "TargetGroupName"
        },
        "Port": 80,
        "Protocol": "TCP",
        "HealthCheckProtocol": "HTTP",
        "VpcId": {
          "Ref": "VpcID"
        },
        "TargetType": "alb",
        "Targets": [
          {
            "Id": {
              "Ref": "ArnAlb"
            },
            "Port": "80"
          }
        ]
      },
      "DependsOn": [
        "LoadBalancer"
      ]
    },
    "LoadBalancer": {
      "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
      "Properties": {
        "IpAddressType": "ipv4",
        "Type": "network",
        "Name": {
          "Ref": "LoadBalancerName"
        },
        "SecurityGroups": {
          "Ref": "SecurityGroupIDs"
        },
        "Subnets": {
          "Ref": "SubnetIDs"
        },
        "Scheme": "internal"
      }
    },
    "Listener": {
      "Type": "AWS::ElasticLoadBalancingV2::Listener",
      "Properties": {
        "DefaultActions": [
          {
            "Type": "forward",
            "TargetGroupArn": {
              "Ref": "TargetGroup"
            }
          }
        ],
        "LoadBalancerArn": {
          "Ref": "LoadBalancer"
        },
        "Port": 80,
        "Protocol": "TCP"
      }
    }
  },
  "Outputs": {
    "ArnNlb": {
      "Description": "The ARN of network load balancer.",
      "Value": {
        "Ref": "LoadBalancer"
      }
    },
    "Listener": {
      "Description": "The arn of listener.",
      "Value": {
        "Ref": "Listener"
      }
    },
    "TargetGroup": {
      "Description": "The arn of target group.",
      "Value": {
        "Ref": "TargetGroup"
      }
    },
    "Sg": {
      "Description": "The arn of listener.",
      "Value": {
        "Fn::GetAtt": ["LoadBalancer", "SecurityGroupIDs"]
      }
    }
  }
}

Note: I have given wrong subnet and security group for security reasons. Please check output section there only something I am not doing right

1 Antwort
0
Akzeptierte Antwort

Im not a CF expert, but according to the docs

this is wrong "Fn::GetAtt": ["LoadBalancer", "SecurityGroupIDs"]

it should be "Fn::GetAtt": ["LoadBalancer", "SecurityGroups"]

profile picture
EXPERTE
beantwortet vor 7 Monaten
  • Yeah, after this I needed to put this "Fn::Join": [",", { "Fn::GetAtt": ["LoadBalancer", "SecurityGroups"] }] for the correct answer. Thank you.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen