Amazon Web Services (AWS) - Get EC2 instance Logs using the AWS CLI

by
Jeremy Canfield |
Updated: August 17 2023
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
The aws ec2 describe-instances command can be used to list your EC2 instances.
aws ec2 describe-instances
--filter can be used to only return the JSON for an specific instance.
aws ec2 describe-instances --filters "Name=tag:Name,Values=my-instance"
Or like this.
aws ec2 describe-instances --filters "Name=tag-value,Values=my-instance"
Something like this should be returned.
{
"Reservations": [
{
"Instances": [
{
"InstanceId": "i-09123475cf14abcd2",
Using the InstanceId, the aws ec2 get-console-output command can be used to return the EC2 instance logs.
aws ec2 get-console-output --instance-id i-00b0224f78537de3c
Often, --output text is included to return the output separated with newlines.
aws ec2 get-console-output --instance-id i-00b0224f78537de3c --output text
Did you find this article helpful?
If so, consider buying me a coffee over at