I’m endlessly fascinated and impressed how inexpensive and accessible powerful computing, networking and data storage has become. Without the likes of AWS, Alibaba Cloud, Microsoft Azure and Google Cloud Platform one wonders if many technologies, services and brands would even exist.
I’ve happily used AWS for many years for my limited and small-scale needs such as when I need computing power to extract files from a large ZIP file or for using a CDN to distribute content. I love that AWS is so quick and simple to use and particularly appreciate the AWS CLI.
Below are a few CLI commands that I tend to use quite often.
Get Started with AWS CLI
Don’t be put off by having to use a command line as using the AWS CLI is really easy. All you need do is download and install the AWS CLI to your local Windows, Linux or Apple computer and follow the configuration instructions provided by AWS.
You are now ready to use the CLI which you do by opening a command prompt and entering the AWS CLI command.
Commonly Used AWS CLI Commands
I’ve listed below a select few commands that I’ve found very useful for my purposes. Of course your needs are likely to differ and AWS provides many examples of commands.
In keeping with AWS documentation I include the
$ in each command below to signify the command prompt however you won’t include the
$ when entering a command at the prompt.
Copy a file from one S3 bucket to another S3 bucket
The cp command specifies copy and, as can be seen, the storage class of REDUCED_REDUNDANCY has been specified for the storage of the file in the destination bucket.
A quick tip: If you are copying a large file then make sure to specify the required storage class at the time of the copy as this will save time (changing the storage class of a large file in S3 can take ages so it’s quickest to do so at the time of the creation of the file).
$ aws s3 cp s3://source-bucket/test.txt s3://destination-bucket/ --storage-class REDUCED_REDUNDANCY
Sync an entire S3 Bucket to another S3 bucket
To sync one S3 bucket with another is achieved using the syntax as below. The default storage class applied is STANDARD so, as above, set the storage class at the time of the sync if you require a different storage class.
$ aws s3 sync s3://source-bucket s3://destination-bucket
List your S3 Buckets
Of course you could go to the AWS GUI to view your S3 buckets however the command below will list your buckets
$ aws s3 ls
Shut-down your EC2 Instance
To be able to shut-down an EC2 instance you’ll need the instance id. The command below will give you various information about your instances. The instance id always stay=ts with
$ aws ec2 describe-instances
Now that we have the instance id we use the following command to stop the EC2 instance.
$ aws ec2 stop-instances --instance-ids i-1234567890abcdefg
The Difference Between Sync and CP
The simplest way of understanding the difference between the sync and cp (copy) commands is that cp is typically used to copy a single files whereas sync is used for multiple files and folders. Adding the –recursive flag added to the cp command however makes the cp act like sync.