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


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 Buy Me A Coffee



Comments


Add a Comment


Please enter b5dd51 in the box below so that we can be sure you are a human.