CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > How to solve: “The availability zones of the specified subnets and the AutoScalingGroup do not match” in CloudFormation?

How to solve: “The availability zones of the specified subnets and the AutoScalingGroup do not match” in CloudFormation?

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 14, 2026 ยท 3 min read ยท 0 Comments
Share: in X

Overview

In this post we will try to solve one of the issue during CloudFormation stack creation or update.

Most of the time we can get this issue during CloudFormation stack update. Because the error message is clearly saying that the currently used subnet’s availability zone and the availability zone defined in AutoScalingGroup is not matching.

Let’s take an example so that it will be easier to understand the problem.

Example 1: Stack is already created and we are trying to update the stack where we have changed the AZs or Subnets.

  • Suppose, we have already created an AutoScalingGroup and that is using the subnet-12345 that is created inside the Availability Zone us-west-2a.
  • Now, we change AZ to us-west-2b and try to update the stack then we may see this error.

Because, the subnet-12345 was created in AZ us-west-2a and subnet does not matches with the new Availability Zone.

Example 2: Creating a new stack

The possibility of this error while creating a new stack:

  • Suppose, we have created our subnet-12345 in availability zone us-west-2a but we set the availability zone us-west-2b.
  • Or, we set value for subnet to subnet-12346 (which was created in availability zone us-west-2b) with us-west-2a.

Solution

Auto Scaling Group will try to launch an instance randomly choosing any one availability zone from the available list. So, from the above example, it may choose an Availability Zone that might not have subnet created. See the code snippet:

MyASG:
    Type: "AWS::AutoScaling::AutoScalingGroup"
    Properties:
      LaunchConfigurationName: !Ref MyLC
      AvailabilityZones: 
        Fn::GetAZs: "" # Thhis will assign all the availability zones from the region where this stack is going to be created/updated
        VPCZoneIdentifier: 
         - subnet-12345 # This subnet is created in us-west-2a

In the above code snippet, If the stack is going to be created in us-west-2 region then, the availability zones would be:

  • us-west-2a
  • us-west-2b
  • us-west-2c
  • us-west-2d

Now, the ASG can pick Availability Zone us-west-2b and we have set subnet subnet-12345. In this case, stack creation/update will fail and shows the error:

The availability zones of the specified subnets and the AutoScalingGroup do not match

Because, Availability Zone and subnet does not match.

So, the solution is: Create at least one subnet inside each availability zone and define the multiple value for VPC zone identifier.

See the updated code:

MyASG:
    Type: "AWS::AutoScaling::AutoScalingGroup"
    Properties:
      LaunchConfigurationName: !Ref MyLC
      AvailabilityZones: 
        Fn::GetAZs: ""
        VPCZoneIdentifier: 
         - subnet-12345 # This subnet is created in us-west-2a
         - subnet-12346 # This subnet is created in us-west-2b
         - subnet-12347 # This subnet is created in us-west-2c
         - subnet-12348 # This subnet is created in us-west-2d

Conclusion

In this post, we learn the possibility of showing the error: The availability zones of the specified subnets and the AutoScalingGroup do not match.

We also learn a possible solution for this.

Related Posts:

  • Consistency and Availability in Distributed System
  • User Defined Exception in Java
  • Pseudo Parameters in AWS CloudFormation
  • Setting Up an EC2 Instance with Amazon CloudFront…
  • Stack Class in Java
  • Region and Availability Zone in AWS
Tags:awscloudformationdevops
Was this article helpful?
โ† Previous ArticleDifference between @PathVariable and @RequestParam
Next Article โ†’Route traffic from AWS Application Load Balancer to EC2 instance running in different VPC

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap