Lab 3‐1: AWS with AWS CLI - seabar24/SYS-360 GitHub Wiki

Installing AWS CLI

Command for installing AWS CLI on Windows:

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi

Command for installing AWS CLI on Linux:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

To update you AWS CLI in Linux:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

Run the command aws –version to see your current AWS CLI version

image

Configuring AWS CLI

To get your AWS CLI keys, enter the AWS Learner Lab and select AWS Details>AWS CLI

Copy down the keys given to the following depending on your OS:

Linux and MAC ~/.aws/credentials

Windows %USERPROFILE%\.aws\credentials

If one of these files do not exist, run the command:

aws configure

From here, add the AWS Access Key ID, Secret Key Access Key to the config and enter the region us-east-1

Creating AWS EC2 Instance

For Launching an Instance in AWS Console, make note of your Key Pair and Security Group name.

Also make note of the AMI-ID for the AMI you want to use (Example: ami-0c7217cdde317cfec is for Ubuntu Server 22.04 LTS)

To run the instance, run the command similar to this with your own image-id, keyname, and security groups:

aws ec2 run-instances --image-id ami-0c7217cdde317cfec --count 1 --instance-type t2.micro --key-name sbarrick-cc --security-groups default --region us-east-1

Output:

image

Connecting to your Instance

From here, SSH to your instance using the key from the keypair you made for the instance and the get the public IP from the aws ec2 describe-instances.

image

Terminating your Instance

For terminating an Instance via AWS CLI, check the instance ID for the Instance you want to terminate

image

Run the command:

aws ec2 terminate-instances –instance-ids <instance-id>

Should get a similar output to this:

image

In the EC2 AWS Console

image