Before you begin, confirm which VPC you’re using (for example, the default VPC in the us-east-2 Ohio region). You can verify the VPC when launching an Amazon Elastic Compute Cloud (EC2) instance or by checking the VPC console. Also ensure you have the CloudFormation stack and template file ready to modify.
- Each dash (-) under SecurityGroupIngress defines a single inbound rule.
- In this example we used the region default VPC; replace the VpcId with the correct VPC for your environment.

Here is a minimal CloudFormation snippet that creates an EC2 instance and a security group with both HTTP and SSH ingress rules. Replace the VpcId and ImageId with values appropriate to your account and region:
Allowing SSH from 0.0.0.0/0 exposes port 22 to the entire Internet. Do not use this for production. Instead, restrict CidrIp to a known IP range (your office/home IP) or use a more secure pattern such as a bastion host or AWS Systems Manager Session Manager for secure access.
- Open the AWS CloudFormation console and select your stack.
- Choose “Update” and upload the modified template (replacing the existing template).
- Proceed through the update steps. The update may take a few minutes to complete.

- In the EC2 console, select the running instance.
- Scroll down to the Security groups section and click the security group link.
- Under the Inbound rules tab, confirm there are two rules: HTTP (port 80) and SSH (port 22), with the expected source CIDR ranges.
You should now be able to connect to the instance on ports 80 and 22 according to the rules you defined. For production environments, follow best practices for access control and monitoring. For more details on CloudFormation and EC2, see the AWS CloudFormation course and the Amazon EC2 course.