How to Use the Command 'aws history' (with examples)
The aws history
command is a useful tool within the AWS Command Line Interface (CLI) that enables users to review the history of AWS CLI commands executed in a session. This history allows users to track their command-line interactions with AWS services, making it easier to troubleshoot issues, maintain documentation, or simply recall the details of previous operations. For this feature to work, the recording of command history must be enabled in the AWS CLI configuration.
Use Case 1: List Command History with Command IDs
Code:
aws history list
Motivation:
Imagine you are debugging a series of AWS CLI commands you executed over the past few hours, and you need to verify the sequence of operations you performed on your AWS resources. Listing the command history with their IDs can be immensely beneficial as it provides a concise and chronological list of all commands executed previously. This helps in identifying any missed steps, repeated actions, or incorrect commands that might have led to unexpected results.
Explanation:
aws
: This is the AWS CLI program, a command-line tool for managing AWS services.history
: This sub-command under the AWS CLI is used to access the history of commands executed.list
: This option is employed to display a list of all previous AWS CLI commands executed, along with their unique command IDs.
Example Output:
CommandId: a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
Date: 2023-10-01 14:23:45
Command: aws s3 ls
CommandId: a2b3c4d5-6789-01bc-def2-22222EXAMPLE
Date: 2023-10-01 15:17:30
Command: aws ec2 describe-instances
Use Case 2: Display Events Related to a Specific Command Given a Command ID
Code:
aws history show a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
Motivation:
Suppose you executed an AWS CLI command that returned an error, and now you need to dissect what went wrong during its execution. By displaying events related to a specific command using its command ID, you can get a detailed view of every interaction that occurred during that command, including input/output and any errors raised. This detailed information is crucial for troubleshooting, learning from execution paths, and ensuring the command’s parameters and configuration were correctly specified.
Explanation:
aws
: Again, this represents the AWS CLI program used to interact with AWS services via the command line.history
: This indicates the command history functionality within the AWS CLI.show
: This directive is used to display detailed information about a specific command’s execution.a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
: This is the unique command ID associated with the specific command whose details are being sought. It serves as an identifier for retrieving detailed execution information.
Example Output:
CommandId: a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
Service: s3
Operation: ListBuckets
Region: us-east-1
Duration: 0.789 seconds
Input: {}
Output: {
"Buckets": [
{
"Name": "example-bucket",
"CreationDate": "2023-09-30T20:04:22.000Z"
}
],
"Owner": {
"DisplayName": "accountname",
"ID": "1234567890"
}
}
Conclusion:
The aws history
command provides invaluable insights into past AWS CLI command executions, aiding in debugging, historical analysis, and documentation of operations. Whether you need an overview of past commands or a deep dive into the details of a specific command, these functionalities can significantly enhance your operational understanding and efficiency when managing AWS resources.