0
votes

I want to replicate the infrastructure from one region(us-east-1) to another(us-east-2). so,I have generated a cloudfromation template of an existing infrastructure with the help of cloudformer tool.

    "asgamazonecsclisetupapijoulebugprodEcsInstanceAsg1EIBNOXSXJ7HD": {
  "Type": "AWS::AutoScaling::AutoScalingGroup",
  "Properties": {
    "AvailabilityZones": [
      "us-east-2b",
      "us-east-2c"
    ],
    "Cooldown": "300",
    "DesiredCapacity": "3",
    "HealthCheckGracePeriod": "300",
    "HealthCheckType": "ELB",
    "MaxSize": "16",
    "MinSize": "3",
    "VPCZoneIdentifier": [
      {
        "Ref": "subnet81c8ebab"
      },
      {
        "Ref": "subnet5df40214"
      }
    ],
    "LaunchConfigurationName": {
      "Ref": "lcamazonecsclisetupapijoulebugprodAMI2017d"
    },
    "LoadBalancerNames": [
      {

        "Ref": "elbJBAPILiveCleanbit2016"
      }
    ],
    "Tags": [
      {
        "Key": "Name",
        "Value": "Live - Cleanbit2016 - joulebug-api",
        "PropagateAtLaunch": true
      }
    ],
    "TerminationPolicies": [
      "Default"
    ]
  }
},
"lcamazonecsclisetupapijoulebugprodAMI2017d": {
  "Type": "AWS::AutoScaling::LaunchConfiguration",
  "Properties": {
    "AssociatePublicIpAddress": true,
    "ImageId": "ami-0e6d83442546978bc",
    "InstanceType": "c3.large",
    "KeyName": "cleanbit2016_vpc",
    "IamInstanceProfile": "amazon-ecs-cli-setup-api-joulebug-prod-EcsInstanceProfile-1M4GOHBP3FP5L",
    "InstanceMonitoring": "true",
    "SecurityGroups": [
      {
        "Ref": "sgCleanbit2016WebServerSG"
      }
    ],
    "BlockDeviceMappings": [
      {
        "DeviceName": "/dev/xvda",
        "Ebs": {
          "SnapshotId": "snap-0b2477be9c863d014",
          "VolumeSize": 8
        }
      },
      {
        "DeviceName": "/dev/xvdcz",
        "Ebs": {
          "VolumeSize": 22
        }
      }
    ]
  }
},
"elbJBAPILiveCleanbit2016": {
  "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
  "Properties": {
    "Policies": [
      {
        "PolicyName": "AWSConsole-SSLNegotiationPolicy-JB-API-Live-Cleanbit2016-1467998170471",
        "PolicyType": "SSLNegotiationPolicyType",
          }
    ],
    }
    }
    "subnet81c8ebab": {
  "Type": "AWS::EC2::Subnet",
  "Properties": {
    "CidrBlock": "10.0.3.0/24",
    "AvailabilityZone": "us-east-2b",
    "VpcId": {
      "Ref": "vpcdcbd08bb"
    },
    "Tags": [
      {
        "Key": "Name",
        "Value": "Cleanbit2016 - Public 1b"
      }
    ]
  }
},
 "sgCleanbit2016WebServerSG": {
  "Type": "AWS::EC2::SecurityGroup",
  "Properties": {
    "GroupDescription": "Web server security group for public subnet in vpc.",
    "VpcId": {
      "Ref": "vpcdcbd08bb"
    },
    "Tags": [
      {
        "Key": "Name",
        "Value": "Cleanbit2016_ WebServerSG"
      }
    ]
  }
},

While launching the template in other region(us-east-2), it is throwing following error:

The requested configuration is currently not supported. Please check the documentation for supported configurations. Launching EC2 instance failed.

4
Is subnet81c8ebab defined elsewhere in your template? That looks similar to a Subnet ID, which would be different each time it is created.John Rotenstein
Yes, It is defined in my template file.Twinkle
I tried your solution then, it is throwing error : Autoscaling group and subnets do not match.Twinkle
Could you please update your question to show either the full template, or at least all elements referenced by the above?John Rotenstein
@JohnRotenstein: I have edited my Question.Please let me know if you want some more code.Twinkle

4 Answers

1
votes

You don't have details of the regions you're using, but if you are trying to do this outside of us-east-1 the Availablility Zones won't work. It also looks like you have a number of other parts of the stack hard-coded, which may not work in another region.

And if you are trying to do this in us-east-1, there is the possibility that one of the AZs is unavailable to you - see this question for more details.

1
votes

You have not provided enough information to be able to diagnose the situation.

I took your template, removed the portions that were incomplete (eg removed the Load Balancer because it was missing Listeners), simplified a few things and it works fine:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Resources": {
        "VPC": {
            "Type": "AWS::EC2::VPC",
            "Properties": {
                "CidrBlock": "10.0.0.0/16",
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "Lab VPC"
                    }
                ]
            }
        },
        "ASG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "AvailabilityZones": [
                    "us-east-2b",
                    "us-east-2c"
                ],
                "Cooldown": "300",
                "DesiredCapacity": "1",
                "HealthCheckGracePeriod": "300",
                "MaxSize": "16",
                "MinSize": "1",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "Subnet1"
                    },
                    {
                        "Ref": "Subnet2"
                    }
                ],
                "LaunchConfigurationName": {
                    "Ref": "LaunchConfig"
                }
            }
        },
        "LaunchConfig": {
            "Type": "AWS::AutoScaling::LaunchConfiguration",
            "Properties": {
                "AssociatePublicIpAddress": true,
                "ImageId": "ami-0b59bfac6be064b78",
                "InstanceType": "t2.micro",
                "InstanceMonitoring": "true",
                "SecurityGroups": [
                    {
                        "Ref": "WebServerSG"
                    }
                ]
            }
        },
        "Subnet1": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "CidrBlock": "10.0.0.0/24",
                "AvailabilityZone": "us-east-2b",
                "VpcId": {
                    "Ref": "VPC"
                },
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "Public 1"
                    }
                ]
            }
        },
        "Subnet2": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "CidrBlock": "10.0.1.0/24",
                "AvailabilityZone": "us-east-2c",
                "VpcId": {
                    "Ref": "VPC"
                },
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "Public 2"
                    }
                ]
            }
        },
        "WebServerSG": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": "Web server security group for public subnet in vpc.",
                "VpcId": {
                    "Ref": "VPC"
                },
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "WebServerSG"
                    }
                ]
            }
        }
    }
}

Therefore, your problem lies in part of the template you did not provide.

You could start with this version, then progressively add back parts of your template until you discover what is causing the error.

0
votes

If you wish to create a CloudFormation template that can run in multiple regions, you should not refer to specific Availability Zones (eg us-east-2b).

You can use Fn::GetAZs - AWS CloudFormation to obtain a list of AZs in region.

0
votes

After a lot of debugging, when I started launching the things manually, I found the same error and I got to know that c3.large is causing the error. When I launch the template with c4.large it successfully launched the template from us-east-1 to us-east-2.