Scale and Load Balance your Architecture: Step-by-Step And Troubleshooting
Initial Setup and Configuration
Project Overview
This guide provides detailed instructions on creating an Amazon Machine
Image (AMI) using the AWS Command Line Interface (CLI). It covers
troubleshooting common issues like connectivity problems, authentication
failures, and provides step-by-step guidance to successfully create an
AMI.
Task 1: Connect to the EC2 Instance
- Use Amazon EC2 Instance Connect to access the instance.
Task 2: Troubleshooting EC2 Connectivity Issues
Instance in Private Subnet:
- Can't use EC2 Instance Connect due to no public IP.
- Consider using a Bastion Host or update subnet to public.
Make Subnet Public:
-
Modify the route table to add a route to the Internet Gateway (IGW):
- Destination: 0.0.0.0/0
- Target: Your Internet Gateway ID (e.g., igw-xxxxxxxx)
-
Enable auto-assign public IPv4 address in subnet settings (if
available).
Assign Public IP to Instance:
-
Either launch a new instance with a public IP or modify the existing
instance's network interface settings.
-
If needed, allocate and associate an Elastic IP:
- Elastic IP -> Actions -> Associate Elastic IP address
Allocate a New Elastic IP Address:
-
Navigate to the EC2 Dashboard in the AWS Management
Console.
- Select Elastic IPs from the left-hand menu.
- Click on Allocate Elastic IP address.
-
Click Allocate to get a new Elastic IP address.
Associate the Elastic IP with Your Instance:
- Select the newly allocated Elastic IP address.
-
Click on Actions >
Associate Elastic IP address.
-
Choose Instance and select your instance from the
dropdown menu.
-
Click Associate. Navigate back to Instance Connect
and it is successful.
Task 3: Install AWS CLI
If not already installed:
sudo apt-get install awscli # For Debian-based
sudo yum install awscli # For RHEL-based systems
Task 4: Configure AWS CLI Config And Credentials
aws configure
- Enter AWS Access Key ID.
- Enter AWS Secret Access Key.
- Set Default region name to us-west-2 (or preferred region).
- Set Default output format to json.
Task 5: Manually Editing Configuration Files In AWS Nano
Edit AWS Config File:
- Due to typos in the CLI I edited in nano
- Open the AWS config file:
nano ~/.aws/config
[default]
output = json
region = us-west-2 # Replace with your preferred region
Edit AWS Credentials File In Nano:
nano ~/.aws/credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
aws_session_token = YOUR_SESSION_TOKEN # If using temporary credentials
Creating the AMI
Verify Instance ID:
curl http://169.254.169.254/latest/meta-data/instance-id
Create the AMI:
aws ec2 create-image \
--instance-id i-<> \
--name "MyCurrentInstanceAMI" \
--description "An AMI for demonstration purposes" \
--no-reboot
Task 6: Dealing With Encountered Issues and Resolutions
AuthFailure Error:
-
Ensured correct AWS Access Key ID, Secret Access Key, and Session
Token in nano.
- Set environment variables manually in CLI:
export AWS_ACCESS_KEY_ID=<your-access-key-id>
export AWS_SECRET_ACCESS_KEY=<your-secret-access-key-id>
export AWS_SESSION_TOKEN=<YOUR_SESSION_TOKEN>
Invalid Region Name:
- Ensure the region is correctly set in the ~/.aws/config file:
[default]
output = json
region = us-west-2
Task 7: Final Steps and Verification
Verify Configuration:
aws configure list
Create the AMI:
aws ec2 create-image \
--instance-id <> \
--name "MyCurrentInstanceAMI" \
--description "An AMI for demonstration purposes" \
--no-reboot
Result:
- Successfully created an AMI with the image ID ami-<>
Summary
- Connected to the instance using EC2 Instance Connect.
-
Troubleshot connectivity issues by considering subnet configurations.
- Modified route table to route traffic to the IGW.
-
Allocated and associated an Elastic IP to ensure the instance had a
public IP.
-
Configured AWS CLI with correct credentials and region settings.
-
Manually edited configuration files to correct any settings issues.
- Set environment variables for temporary credentials.
-
Verified instance ID and created the AMI using the AWS CLI command.
-
Resolved AuthFailure error by verifying and correctly setting
credentials.
- Successfully created an AMI of the instance
These detailed steps should help you understand and replicate the process
of configuring network settings for EC2 instance connect and creating an
AMI using AWS CLI as well as trouble shooting errors that might happen in
the process.