0
votes

I wrote a simple cloudformation template that has few parameters. All parameters work. But when I pass Availability zone, the template gives error during creation saying "not a valid availability zone". Here is my error and code below:

11:48:47 UTC-0700 CREATE_FAILED AWS::EC2::Instance EC2Instance Invalid availability zone:

   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "EC2 Head Node Instance ",
       "Parameters": {
              "AZ": {
               "Description": "Availablity Zone",
               "Type": "String"

    },
    "Region":{
        "Description": "Dev/Test/Prod regions",
        "Type": "String"
    },
    "AMI": {
        "Description": "AMI to start virtual server",
        "Type": "String",
        "MaxLength": 12,
        "MinLength": 12
    },

    "Subnet": {
        "Description": "subnet to launch virtual server in",
        "Type": "AWS::EC2::Subnet::Id"
    }

},
"Resources": {
    "EC2Instance": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "ImageId": {"Ref": "AMI"},
            "SubnetId": {"Ref": "Subnet"},
            "AvailabilityZone": {"Ref":"AZ"},
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "QRM Head Node in DEV region"
                }
            ]
            }
        }

},
"Outputs": {
    "InstanceId": {
        "Value": {"Ref": "EC2Instance"},
        "Description": "ID of virtual server"
    },

    "PublicIPAddress": {
        "Value": {"Fn::GetAtt": ["EC2Instance", "PublicIp"]},
        "Description": "public IP address of virtual server"
    }
 }

}

1
You do not really need availability zone as a parameter in your CloudFormation template since you have subnet ID as a parameter as well, subnets in VPC cannot span multiple AZs. I'm assuming that the error comes from the fact that you select availability zone, for example, eu-west-1a and a subnet that is associated with for example eu-west-1c. Region parameter is unnecessary as well since CloudFormation is a regional service, not global.Michal Gasek

1 Answers

0
votes

Just change your parameter to:

"Parameters": {
    "AZ": {
         Description": "Availability Zone of the Subnet",
         "Type": "AWS::EC2::AvailabilityZone::Name"
     },
     ....
 }