0

I'm designing a cloudformation to deploy ALB and i got an error that says:

At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; 

These network was created by other Cloudformation. And now, i go to VPC / SUbnets and i see both created.

The part of code where im defining the subnets in ELB creation is this:

        "Subnets": [
          {
            "Fn::ImportValue": {
              "Fn::Join": [
                "-",
                [
                  {
                    "Ref": "ParentSubnetStackName"
                  },
                  "PublicSubnet1ID"
                ]
              ]
            },
            "Fn::ImportValue": {
              "Fn::Join": [
                "-",
                [
                  {
                    "Ref": "ParentSubnetStackName"
                  },
                  "PrivateSubnet2ID"
                ]
              ]
            }
          }
        ],

The only thing that i think that could be a problem is than im importing by other stack than i dont executing at the same time of this cloudformation.. I don't know if there could be a problem, because the Subnets are created at this moment for sure and they belong to differents AZ.

EDIT:

@jogold The CF is too long. I attach here a piece of the code

 "PublicSubnet1": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Fn::ImportValue": {
                        "Fn::Join": [
                            "-",
                            [
                                {
                                    "Ref": "ParentStackName"
                                },
                                "VPCID"
                            ]
                        ]
                    }
                },
                "CidrBlock": {
                    "Ref": "PublicSubnet1CIDR"
                },
                "AvailabilityZone": {
                    "Ref": "AZ1"
                },
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "AWS::StackName"
                                    },
                                    "PublicSubnet1"
                                ]
                            ]
                        }
                    }
                ]
            }

And after in the outputs i export it:

 "PublicSubnet1": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Fn::ImportValue": {
                        "Fn::Join": [
                            "-",
                            [
                                {
                                    "Ref": "ParentStackName"
                                },
                                "VPCID"
                            ]
                        ]
                    }
                },
                "CidrBlock": {
                    "Ref": "PublicSubnet1CIDR"
                },
                "AvailabilityZone": {
                    "Ref": "AZ1"
                },
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "AWS::StackName"
                                    },
                                    "PublicSubnet1"
                                ]
                            ]
                        }
                    }
                ]
            }

All the subnets are created bye the same way.

  • When you go in the console to VPC / Console, what do you see in the column Availability Zone for your subnets? – jogold May 07 '19 at 14:10
  • I see different AZ in each subnets,, eu-west-1a and eu-west-1b –  May 07 '19 at 14:25
  • Can you add the template of the stack deploying your subnets? – jogold May 07 '19 at 14:28
  • I just posted like answer because the message was too long to post here. –  May 07 '19 at 14:36
  • Please edit your question to include the template, as suggested. If you get the availability zones error, it means that something is not right with your subnets. Maybe you are referencing wrong subnets. You can try to create your LB in the console first to debug. – jogold May 07 '19 at 16:15
  • I tried to create the LB in the console and it works, but using the same subnets in the cloudformation, it doesnt work.. I don't know where is the problem.. –  May 08 '19 at 07:08

0 Answers0