0
0
AWScloud~5 mins

Basic CLI commands (s3, ec2) in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing cloud resources can be tricky without the right tools. AWS CLI commands let you control storage and servers easily from your computer without using the web console.
When you want to upload or download files to cloud storage quickly without opening a browser.
When you need to check the status of your virtual servers to see if they are running.
When you want to start or stop a virtual server to save costs during off-hours.
When you want to list all your storage buckets or servers to keep track of your resources.
When automating tasks like backups or server management using scripts.
Commands
This command lists all your S3 storage buckets so you can see what storage spaces you have.
Terminal
aws s3 ls
Expected OutputExpected
2023-05-01 10:00:00 example-bucket 2023-06-15 15:30:00 my-app-data
This command uploads the file 'sample.txt' from your computer to the 'example-bucket' in S3 storage.
Terminal
aws s3 cp sample.txt s3://example-bucket/sample.txt
Expected OutputExpected
upload: ./sample.txt to s3://example-bucket/sample.txt
This command shows details about your virtual servers (EC2 instances), including their status and IDs.
Terminal
aws ec2 describe-instances
Expected OutputExpected
{ "Reservations": [ { "Instances": [ { "InstanceId": "i-0123456789abcdef0", "State": {"Name": "running"}, "InstanceType": "t2.micro" } ] } ] }
This command stops the EC2 instance with the given ID to save costs when the server is not needed.
Terminal
aws ec2 stop-instances --instance-ids i-0123456789abcdef0
Expected OutputExpected
{ "StoppingInstances": [ { "InstanceId": "i-0123456789abcdef0", "CurrentState": {"Name": "stopping"}, "PreviousState": {"Name": "running"} } ] }
--instance-ids - Specifies which server to stop by its unique ID
This command starts the EC2 instance again so it can run and serve your applications.
Terminal
aws ec2 start-instances --instance-ids i-0123456789abcdef0
Expected OutputExpected
{ "StartingInstances": [ { "InstanceId": "i-0123456789abcdef0", "CurrentState": {"Name": "pending"}, "PreviousState": {"Name": "stopped"} } ] }
--instance-ids - Specifies which server to start by its unique ID
Key Concept

If you remember nothing else, remember: AWS CLI commands let you control storage and servers quickly from your computer without using the web interface.

Common Mistakes
Using incorrect bucket or instance IDs in commands
The commands will fail because AWS cannot find the resource you want to manage.
Always double-check the bucket names and instance IDs before running commands.
Trying to upload files to a bucket that does not exist
The upload will fail because the destination storage space is missing.
List your buckets first with 'aws s3 ls' and create the bucket if needed.
Not having AWS CLI configured with credentials
Commands will fail with permission errors because AWS does not know who you are.
Run 'aws configure' to set up your access key, secret key, region, and output format.
Summary
Use 'aws s3 ls' to list your storage buckets and 'aws s3 cp' to upload files.
Use 'aws ec2 describe-instances' to see your virtual servers and 'aws ec2 stop-instances' or 'start-instances' to control them.
Always verify resource names and IDs before running commands to avoid errors.