Home > Blockchain >  Cloudformation error:Invalid availability zone: [ap-southeast-2] (Service: AmazonEC2; Status Code: 4
Cloudformation error:Invalid availability zone: [ap-southeast-2] (Service: AmazonEC2; Status Code: 4

Time:10-03

I queried the imageid and used that in the cloudformation template but it seems to be failing with "Invalid availability zone: [ap-southeast-2] (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 92ae3703-c957-4cb2-8bc3-84a48d3e02d4; Proxy: null)"

aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --region ap-southeast-2
{
    "InvalidParameters": [], 
    "Parameters": [
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2", 
            "DataType": "text", 
            "LastModifiedDate": 1630616391.045, 
            "Value": "ami-0210560cedcb09f07", 
            "Version": 51, 
            "Type": "String", 
            "ARN": "arn:aws:ssm:ap-southeast-2::parameter/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
        }
    ]

This one fails

Resources:
 Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      AvailabilityZone: ap-southeast-2
      ImageId: ami-0210560cedcb09f07
      InstanceType: t2.micro

but the following one seems to work

# Use public Systems Manager Parameter
Parameters:
  LatestAmiId:
    Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'

Resources:
 Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: !Ref LatestAmiId
      InstanceType: t2.micro

CodePudding user response:

ap-southeast-2 is region name. Availability zones end with a, b, c`. So you should have, for example :

AvailabilityZone: ap-southeast-2a
  • Related