We can launch an EC2 instance by following these steps:
- Go to the EC2 dashboard.
- Click on Instances from the left sidebar.
- Click on the Launch Instance button at the top of the page.
- Select Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-00dc79254d0461090 (64-bit x86).
- On the Choose an Instance Type page, set Type to t2.micro and click Next: Configure Instance Details.
- Within the Configure Instance Details page, either choose a custom VPC or the default one. You can also add user data that will be executed during the launch.
- We can use the default configuration in the Add Storage page. Click Next: Add Tags.
- On the Add Tags page, add a tag with Key set to Name. For Value, enter a meaningful name. Click on Next: Configure Security Group.
Tags are not mandatory, but a tag with Key set to Name can help us identify our EC2 instances easily from the list of EC2 instances in the EC2 dashboard.
- On the Configure Security Group page, either choose an existing security group or create a new security group. Exact permission rules for the security group are provided under the respective recipes.
- On the Review Instance Launch page, review the configuration and click on Launch.
- We can use an existing key pair and click on Launch Instances, or we can create a new key pair and launch an instance, as follows:
- Select the Create a new key pair option.
- Click on Download Key Pair to download the key. Save the key safely. If you are using a Unix or Mac system, then change its file permission (chmod) to 400.
- Click on Launch Instances.
- Click on View Instances and wait until our instance's Instance State is changed to running and the Status Checks field has no errors.
- Click on our instance and check the summary.
- We can SSH into our EC2 instance with the following command on a Mac or Linux machine. The exact command or steps may differ between operating systems:
ssh -i aws-sec-cb-demo-kp.pem ec2-user@54.145.102.218
Here, aws-sec-cb-demo-kp.pem is the key pair's private key file we downloaded in step 11.