CodexBloom - Programming Q&A Platform

AWS CloudFormation Stack Rollback scenarios with 'ResourceNotReady' scenarios During EC2 Instance Provisioning

πŸ‘€ Views: 1 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-08
aws cloudformation ec2 YAML

I'm reviewing some code and I've been banging my head against this for hours. I've looked through the documentation and I'm still confused about I'm sure I'm missing something obvious here, but I've been struggling with this for a few days now and could really use some help... I'm trying to create a CloudFormation stack that provisions an EC2 instance with an associated Elastic IP and security group. However, during the stack creation process, I encounter a `ResourceNotReady` behavior that leads to a rollback. The behavior message states: `Resource handler returned message: "Resource creation failed for 'MyInstance'. Reason: 'The instance status is not ready.'" I’ve verified that my EC2 instance type is valid in the specified region (us-east-1), and the AMI ID used is also available. Here’s the relevant snippet of my CloudFormation template: ```yaml Resources: MySecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow SSH access SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 MyElasticIP: Type: AWS::EC2::EIP MyInstance: Type: AWS::EC2::Instance Properties: InstanceType: t2.micro KeyName: my-key-pair ImageId: ami-0abcdef1234567890 SecurityGroupIds: - !Ref MySecurityGroup Ipv6AddressCount: 1 Ipv6Addresses: - Ipv6Address: 2001:db8:1234:1a00::1 NetworkInterfaces: - AssociatePublicIpAddress: true DeviceIndex: '0' Ebs: VolumeSize: 20 SubnetId: subnet-12345678 DeleteOnTermination: true ``` I've ensured that the subnet and security group exist, but the behavior continues. I tried adding a `CreationPolicy` to allow more time for the instance to initialize, which did not help. Has anyone else encountered this scenario, or can anyone suggest further debugging steps? I'm also open to any best practices regarding EC2 instance provisioning in CloudFormation. What's the best practice here? For context: I'm using Yaml on Windows. What's the best practice here? Any ideas what could be causing this? For reference, this is a production microservice. Could this be a known issue? I'm working with Yaml in a Docker container on Linux. Could this be a known issue? I'm developing on Ubuntu 20.04 with Yaml. Any examples would be super helpful. This is happening in both development and production on Linux.