Create and Configure AWS CLI in an EC2 Instance
Written on
Introduction to AWS EC2
In this guide, we'll walk through the process of creating and launching an EC2 instance, connecting to it via SSH, and configuring the AWS CLI. Don't worry; it's straightforward!
Steps to Follow:
- Create and launch an EC2 instance.
- SSH into the EC2 instance.
- Configure the AWS CLI.
To begin, log into your AWS account. Upon logging in, you should see "EC2" among your recently visited services. If it's not visible, simply type "EC2" in the search bar at the top and select it.
Next, click on "Instances" to view your current instances.
Now, let's proceed to launch a new instance. You'll notice multiple options available for launching; choose the one that suits you best.
For this instance, I have named it "Developer Exercise 1."
Next, we need to create a key pair.
I recommend naming your instance and key pair the same for easy identification, especially if you're working on multiple projects. After naming your key pair, click "Create." Remember where your key pair is saved for later access.
Once the instance is launched, select "View all instances" to proceed.
Next, check the box next to your instance and click "Connect."
Choose "SSH client" and copy the provided command. This command is essential for connecting to your instance.
Open your terminal, navigate to the directory containing your key pair, and paste the command. My key pair is located in my Downloads folder, as shown below.
Success! You are now logged in as ec2-user and operating within your EC2 instance. To configure the AWS CLI, simply enter the command:
aws configure
You will be prompted to input your AWS Access Key ID and AWS Secret Access Key. If you don’t know these, no worries! Just follow these steps to create new keys.
Back in your AWS dashboard, click on the dropdown next to your Username and Account ID, then select "Security credentials."
Then, select "Create access key" to download your new keys.
Open the file containing your downloaded keys. If you're having trouble copying them directly into your terminal, try using a split-screen view for easier manual entry.
Re-enter the earlier command, and you will be prompted again for your keys. Enter them along with your default region name. After completing this, run the command once more to confirm the configuration. Note that I skipped the output format setting.
And just like that, you're all set! This process was designed to be simple, and it truly was.
Pro Tip: Always keep track of your Access Keys to streamline the process in the future.
Thank you for following along! I hope you found this guide helpful.
Jason Wood
@jwood9799
Chapter 2: YouTube Tutorials
This video tutorial titled "AWS CLI on Amazon EC2" provides a comprehensive overview of setting up the AWS CLI in an EC2 environment.
In this second video, "Launch Amazon EC2 Instance Using AWS CLI," you'll learn the step-by-step process to launch an EC2 instance through the AWS CLI.