Using AWS with Linux
Introduction
Amazon Web Services (AWS) is a comprehensive, evolving cloud computing platform provided by Amazon. It offers a mix of infrastructure as a service (IaaS), platform as a service (PaaS), and packaged software as a service (SaaS) offerings. This tutorial will guide you through the process of using AWS with a Linux operating system from start to finish.
Prerequisites
Before you begin, ensure you have the following:
- An AWS account
- Basic knowledge of Linux commands
- A Linux system or server
Installing AWS CLI on Linux
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. To install AWS CLI on Linux, follow these steps:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Verify the installation:
aws --version
Configuring AWS CLI
After installing AWS CLI, configure it using your AWS credentials:
aws configure
You will be prompted to enter your AWS Access Key ID, Secret Access Key, region, and output format:
AWS Secret Access Key [None]:
Default region name [None]:
Default output format [None]:
Launching an EC2 Instance
To launch an EC2 instance using AWS CLI, execute the following command:
aws ec2 run-instances --image-id ami-0abcdef1234567890 --count 1 --instance-type t2.micro --key-name MyKeyPair --security-groups my-sg
Replace the placeholders with your own values:
--image-id
: The ID of the AMI (Amazon Machine Image) to use--count
: Number of instances to launch--instance-type
: The type of instance to launch--key-name
: The name of the key pair to use--security-groups
: The security group to associate with the instance
Managing EC2 Instances
To list your running EC2 instances, use:
aws ec2 describe-instances
To stop an instance:
aws ec2 stop-instances --instance-ids i-0abcdef1234567890
To start an instance:
aws ec2 start-instances --instance-ids i-0abcdef1234567890
To terminate an instance:
aws ec2 terminate-instances --instance-ids i-0abcdef1234567890
Using S3 with AWS CLI
Amazon S3 (Simple Storage Service) is an object storage service. To create a new bucket:
aws s3 mb s3://my-new-bucket
To list all buckets:
aws s3 ls
To upload a file to a bucket:
aws s3 cp myfile.txt s3://my-new-bucket/
To download a file from a bucket:
aws s3 cp s3://my-new-bucket/myfile.txt ./
Conclusion
In this tutorial, you learned how to use AWS with a Linux system. You installed and configured AWS CLI, launched and managed EC2 instances, and used S3 for storage. AWS offers a vast array of services, and the CLI is a powerful tool to manage your cloud resources efficiently.