In this lab a new VPC will be created with a public subnet. An Internet Gateway and Route Table will be attached in order to allow a EC2 Instance to communicate with internet
- Create VPC
- Create a subnet and an internet gateway
- Configure routing for your VPC using a route table
- Create and manage an EC2 instance and an associated Elastic IP Address (EIP) within your VPC
- AWS account
- In Management Console go to VPC and create a new one with following values: CIDR block: 10.0.0.0/16, No IPv6 CIDR block, tenancy: default.
- Create a new Subnet. VPC ID: choose the one created in previous step. Give it a name to indicate that it’ll be a public subnet, choose an AZ and provide CIDR block: 10.0.0.0/24.
- Create a new Internet Gateway for your previously created VPC. Then attach the IGW to the VPC
- Add routes to your previously created VPC route table. Choose the route associated with your VPC, and in Routes tab click on Edit routes. Then Add route and set the values to Destination: 0.0.0.0/0 and Target: choose Internet Gateway and then select the previously-created one.
- Create an EC2 instance inside your VPC. Navigate to EC2 and launch instance (Amazon Linux 2, t2.micro). Make sure that under Network you choose your VPC and enable assigning of Public IPv4 address. Create a new Security Group that will allow All CIMP – IPv4 from anywhere inbound traffic.
- Once your instance is running, copy the IPv4 Public IP and try pinging it from you computer:
- Allocate an EIP and associate it with your EC2 instance. Navigate to VPC tab and Allocate Elastic IP address. Then select it and from Actions choose Associate Elastic IP address. Provide the following values: Resource type: Instance, Instance: your earlier created instance, Private IP leave blank.
- Now if you ping that Elastic IP you should get responses from instance.