Amazon EC2 (Elastic Compute Cloud) is one of the most popular services in AWS, allowing you to launch and manage virtual machines in the cloud. In this guide, we’ll walk through creating a Demo EC2 instance using the Amazon Linux AMI and a t2.micro free-tier instance type. We’ll also add a simple user data script to run on startup.
Prerequisites
- An AWS account
- Basic familiarity with AWS Management Console
Step 1: Log in to AWS Management Console
- Head over to AWS Console.
- From the Services menu, search for EC2 and click on it.
Step 2: Launch an Instance
- Click Launch instance.
- Give your instance a name:
Demo EC2
.
Step 3: Choose Amazon Machine Image (AMI)
- In the Application and OS Images section, choose:
- Amazon Linux (Free Tier eligible).
⚡ Step 4: Select Instance Type
- From the Instance type dropdown, select:
- t2.micro (Free Tier eligible).
Step 5: Configure User Data (Startup Script)
- Scroll down to Advanced details.
- In the User data section, paste the following script:
#!/bin/bash
echo "Hurray!!! We got this working" > /home/ec2-user/startup.txt
This script will create a file named
startup.txt
with the message inside.
Step 6: Configure Key Pair
- Either select an existing key pair or create a new one.
- This will allow you to SSH into your instance later.
Step 7: Configure Network Settings
- Choose default VPC and subnet (unless you want custom networking).
- Allow SSH traffic from your IP.
- Allow HTTP traffic from the internet.
Step 8: Launch the Instance
- Review all settings.
- Click Launch instance.
Your Demo EC2 instance will now spin up in the cloud!
Step 9: Verify User Data Script
- Once the instance is running, select connect for EC2 Instance Connect.
- Ensure the Connection type is set to
Connect using a Public IP
,Puplic IPv4 address
is selected and the Username isec2-user
; then selectConnect
.
We have now successfully connected to the Amazon Linux 2023 machine:
- Run:
cat /home/ec2-user/startup.txt
- You should see:
Hurray!!! We got this working
Conclusion
In just a few steps, you’ve launched your first Amazon EC2 instance using Amazon Linux on a t2.micro free-tier machine. With the user data script, we confirmed automation works right at startup.
Next steps: Try customizing the user data script to install software packages, run web servers, or deploy applications automatically.
Top comments (0)