AWS CLI (Command Line Interface) "is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts" (AWS). Users are mostly familiar with the AWS Management Console to access and manage the various AWS services. However with the help of AWS command line interface, users can access and manage those same services through command-line shells. Common shell programs include bash or Z Shell on Linux or macOS and PowerShell on Windows.
In addition, we have the ability to run AWS CLI commands on a EC2 server after connecting to the EC2 server from our local machine through SSH or PuTTY. This respository illustrates the steps to remotely configure AWS CLI on an Amazon Linux 2 EC2 instance. Initially, we launch an EC2 instance, create our IAM user and attach the appropriate user's policy. Then, we connect to the instance through SSH, configure AWS CLI and execute commands from the instance such as listing the user's S3 buckets. The steps can be applied using other Amazon Machine Images (AMIs) such as Windows, macOS and Redhat.
Note:
- Please remember to always secure and never share your EC2's private key and the user's credentials.
- In this example, all public IP addresses were temporarly allowed into the EC2 instance on port 22 to use the SSH protocol for test and learning purposes only. Please make sure to secure access to your EC2 by setting up the appropriate firewall rules.
- AWS charges users based on the amount of compute, storage and data transfer out (not in). This example uses the EC2 instance (t2.micro) family that comes with an attached 8gb SSD EBS volume. Both are covered under the AWS 1-year free tier model. Every user's setup is different. Thus depending on your personal AWS setup, please remember to disable or terminate any running EC instances/EBS volumes as it can incur charges within your account.
- Note that our Linux 2 AMI instance comes pre-installed with AWS CLI and Python.
- It is recommennded to update our EC2 instance and CLI prior to use (I ommitted this step for quick CLI configuration and testing).
- Leaving "Default output format" empty means receiving the default output format in json string
- Note: It will list the newly created bucket in step 4