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
Yeah, after this I needed to put this "Fn::Join": [",", { "Fn::GetAtt": ["LoadBalancer", "SecurityGroups"] }] for the correct answer. Thank you.