AWS EC2 goes to stopped state when creating it

1.4k Views Asked by At

I am creating an AWS EC2 instance in a VPC with internet access using cloudformation. I am able to create the EC2 as expected based on the JSON. But it seems like the instance state goes to stopped soon after creating the EC2. I was expecting the EC2 to be up and in running state as soon as created.

Has anyone faced this problem?

I am able to go to the AWS console and manually make the instance to running state successfully though.

Here is the JSON for EC2

    "PublicEC2Instance": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "ImageId": {
                "Fn::FindInMap": ["AWSRegionArch2AMI", {
                        "Ref": "AWS::Region"
                    },
                    "64"
                ]
            },
            "InstanceType": {
                "Ref": "InstanceType"
            },
            "KeyName": {
                "Ref": "KeyPair"
            },

            "BlockDeviceMappings": [{
                "DeviceName": "/dev/sda1",
                "Ebs": {
                    "VolumeSize": "8"
                }
            }, {
                "DeviceName": "/dev/sdm",
                "Ebs": {
                    "VolumeSize": "8"
                }
            }],
            "Tags": [{
                "Key": "Name",
                "Value": "Sample-PublicEC2"
            }],
            "UserData": {
                "Fn::Base64": {
                    "Ref": "WebServerPort"
                }
            },
            "NetworkInterfaces": [{
                "AssociatePublicIpAddress": "true",
                "DeleteOnTermination": "true",
                "DeviceIndex": "0",
                "SubnetId": {
                    "Ref": "PublicSubnet"
                },
                "GroupSet": [{
                    "Ref": "PublicSecurityGroup"
                }]
            }]
        }

    }
1

There are 1 best solutions below

2
On BEST ANSWER

The UserData in your template looks invalid. It's possible that the instance startup aborts on invalid data. Try removing this property and creating the stack again.

If this doesn't solve the problem, you can try looking at the console output of the stopped instance for more information. See Getting Console Output and Rebooting Instances for instructions on how to do this using the AWS Management Console.