๐Ÿงช Lab 7: Cloud Automation with AWS CLI

Course: CompTIA Cloud+ CV0-004
Objective: Automate cloud resource management using the AWS CLI.


๐ŸŽฏ Goals


๐Ÿ› ๏ธ Part 1: Install and Configure AWS CLI

1. Install AWS CLI

Follow the instructions for your OS:
- https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

2. Configure CLI

aws configure

Provide: - AWS Access Key ID
- AWS Secret Access Key
- Region (e.g., us-east-1)
- Output format: json

โœ… Checkpoint: Run aws ec2 describe-instances to test.


๐Ÿงฑ Part 2: Create a VPC, Subnet, and Internet Gateway

aws ec2 create-vpc --cidr-block 10.0.0.0/16
aws ec2 create-subnet --vpc-id <vpc-id> --cidr-block 10.0.1.0/24
aws ec2 create-internet-gateway
aws ec2 attach-internet-gateway --internet-gateway-id <igw-id> --vpc-id <vpc-id>

Replace <vpc-id> and <igw-id> with your actual values.


๐Ÿš€ Part 3: Launch EC2 Instance with CLI

aws ec2 run-instances   --image-id ami-0abcdef1234567890   --count 1   --instance-type t2.micro   --key-name cloudplus-key   --security-group-ids <sg-id>   --subnet-id <subnet-id>   --associate-public-ip-address

โœ… Checkpoint: Confirm instance in AWS Console or use CLI:

aws ec2 describe-instances

๐Ÿงฉ Part 4: Bash Script Example (Optional)

Save as launch.sh:

#!/bin/bash
# Create VPC
vpc_id=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query 'Vpc.VpcId' --output text)

# Other AWS CLI commands go here
echo "VPC created: $vpc_id"

Run with:

chmod +x launch.sh
./launch.sh

โœ… Lab Complete