aws-ec2
Manage Amazon EC2 instances from command line
TLDR
Display information about a specific instance
Display information about all instances
Display information about all EC2 volumes
Delete an EC2 volume
Create a snapshot from an EC2 volume
List available AMIs (Amazon Machine Images)
Show list of all available EC2 commands
Display help for specific EC2 subcommand
SYNOPSIS
aws ec2
[subcommand]
[options]
[--output
[--region
[--profile
PARAMETERS
run-instances
Launches one or more EC2 instances based on specified configurations (e.g., image ID, instance type, security group, key pair).
describe-instances
Retrieves detailed information about one or more EC2 instances, allowing filtering by instance IDs, tags, or other attributes.
stop-instances
Stops one or more running EC2 instances. Stopped instances retain their root device volume and most of their attributes.
start-instances
Starts one or more stopped EC2 instances.
terminate-instances
Terminates one or more EC2 instances. Terminated instances cannot be restarted and their data on ephemeral storage is lost.
create-volume
Creates an Amazon EBS (Elastic Block Store) volume with a specified size, availability zone, and type.
attach-volume
Attaches an Amazon EBS volume to a running instance.
describe-security-groups
Describes one or more EC2 security groups, which control inbound and outbound traffic for instances.
authorize-security-group-ingress
Adds an ingress (inbound) rule to a security group.
DESCRIPTION
The aws ec2 command is a fundamental part of the AWS Command Line Interface (CLI), providing a powerful and direct way to interact with Amazon Elastic Compute Cloud (EC2) services from your terminal. It enables users to automate, script, and programmatically manage their EC2 instances, Amazon EBS volumes, security groups, key pairs, and other related resources.
Through aws ec2, you can perform a wide range of operations, including launching new instances (run-instances), retrieving detailed information about existing instances (describe-instances), stopping or terminating instances (stop-instances, terminate-instances), creating and attaching volumes (create-volume, attach-volume), and configuring network settings.
The AWS CLI supports various output formats like JSON, text, and table, making it easy to integrate with other command-line tools or scripts. It is an indispensable tool for developers, DevOps engineers, and system administrators who manage cloud infrastructure in AWS.
CAVEATS
Using aws ec2 requires the AWS CLI to be installed and properly configured with valid AWS credentials.
All actions performed via aws ec2 interact directly with your AWS account and may incur charges, so it's crucial to understand the cost implications of operations like launching instances or creating volumes.
Proper IAM permissions are essential for each command; insufficient permissions will result in 'Access Denied' errors.
The command's output is typically JSON, which often requires tools like jq(1) for effective parsing and filtering in shell scripts.
<B>AUTHENTICATION AND CONFIGURATION</B>
Before using aws ec2 commands, you must configure your AWS CLI. This is typically done by running aws configure, which prompts for your AWS Access Key ID, Secret Access Key, default region, and preferred output format. These credentials and configurations are stored in ~/.aws/credentials and ~/.aws/config. Alternatively, you can use environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) or leverage IAM roles for EC2 instances, which automatically provide temporary credentials.
<B>ERROR HANDLING AND DEBUGGING</B>
If a command fails, aws ec2 often provides detailed error messages. Using the --debug option can yield even more verbose output, including the full HTTP request and response, which is invaluable for troubleshooting connectivity issues, permission problems, or incorrect parameters. Always check the AWS CLI documentation for specific error codes and their remedies.
HISTORY
The AWS CLI, which includes the aws ec2 subcommand, was initially released by Amazon Web Services in 2013. Prior to its introduction, users often relied on separate command-line tools for different AWS services or specific SDKs. The AWS CLI consolidated these functionalities into a single, unified command-line interface, significantly improving scripting capabilities and ease of management for AWS resources. Its development has focused on consistency across services, supporting various authentication methods, and providing robust filtering and output options, making it a cornerstone for automation in AWS environments.