Awslogs - AWS CloudWatch logs for Humans™

Overview

awslogs

https://badge.fury.io/py/awslogs.png https://travis-ci.org/jorgebastida/awslogs.png?branch=master

awslogs is a simple command line tool for querying groups, streams and events from Amazon CloudWatch logs.

One of the most powerful features is to query events from several streams and consume them (ordered) in pseudo-realtime using your favourite tools such as grep:

$ awslogs get /var/log/syslog ip-10-1.* --start='2h ago' | grep ERROR

Features

  • Aggregate logs from across streams.
    • Aggregate all streams in a group.
    • Aggregate streams matching a regular expression.
  • Colored output.
  • List existing groups
    • $ awslogs groups
  • List existing streams
    • $ awslogs streams /var/log/syslog
  • Watch logs as they are created
    • $ awslogs get /var/log/syslog ALL --watch
  • Human-friendly time filtering:
    • --start='23/1/2015 14:23'
    • --start='2h ago'
    • --start='2d ago'
    • --start='2w ago'
    • --start='2d ago' --end='1h ago'
  • Retrieve event metadata:
    • --timestamp Prints the creation timestamp of each event.
    • --ingestion-time Prints the ingestion time of each event.

Example

Running: awslogs get /var/logs/syslog ALL -s1d will return you events from any stream in the /var/logs/syslog group generated in the last day.

https://github.com/jorgebastida/awslogs/raw/master/media/screenshot.png

Installation

You can easily install awslogs using pip:

$ pip install awslogs

If you are on OSX El Capitan, use the following (Why? Check Donald Stufft's comment here)

$ pip install awslogs --ignore-installed six

You can also install it with brew:

$ brew install awslogs

Options

  • awslogs groups: List existing groups
  • awslogs streams GROUP: List existing streams withing GROUP
  • awslogs get GROUP [STREAM_EXPRESSION]: Get logs matching STREAM_EXPRESSION in GROUP.
    • Expressions can be regular expressions or the wildcard ALL if you want any and don't want to type .*.

Note: You need to provide to all these options a valid AWS region using --aws-region or AWS_REGION env variable.

Time options

While querying for logs you can filter events by --start -s and --end -e date.

  • By minute:

    • --start='2m' Events generated two minutes ago.
    • --start='1 minute' Events generated one minute ago.
    • --start='5 minutes' Events generated five minutes ago.
  • By hours:

    • --start='2h' Events generated two hours ago.
    • --start='1 hour' Events generated one hour ago.
    • --start='5 hours' Events generated five hours ago.
  • By days:

    • --start='2d' Events generated two days ago.
    • --start='1 day' Events generated one day ago.
    • --start='5 days' Events generated five days ago.
  • By weeks:

    • --start='2w' Events generated two week ago.
    • --start='1 week' Events generated one weeks ago.
    • --start='5 weeks' Events generated five week ago.
  • Using specific dates:

    • --start='23/1/2015 12:00' Events generated after midday on the 23th of January 2015.
    • --start='1/1/2015' Events generated after midnight on the 1st of January 2015.
    • --start='Sat Oct 11 17:13:46 UTC 2003' You can use detailed dates too.

    Note, for time parsing awslogs uses dateutil.

  • All previous examples are applicable for --end -e too.

Filter options

You can use --filter-pattern if you want to only retrieve logs which match one CloudWatch Logs Filter pattern. This is helpful if you know precisely what you are looking for, and don't want to download the entire stream.

For example, if you only want to download only the report events from a Lambda stream you can run:

$ awslogs get my_lambda_group --filter-pattern="[r=REPORT,...]"

Full documentation of how to write patterns: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/FilterAndPatternSyntax.html

JSON logs

In a similar way than the aws-cli command, you can use --query to filter each of your json log lines and extract certain fields:

$ awslogs get my_lambda_group --query=message

This will only display the message field for each of the json log lines.

Using third-party endpoints

If you use tools like localstack, fakes3 or other, consider to change boto3 endpoint using --aws-endpoint-url or AWS_REGION env variable.

AWS IAM Permissions

The required permissions to run awslogs are contained within the CloudWatchLogsReadOnlyAccess AWS managed permissions. As of 2020-01-13, these are the permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "logs:Describe*",
                "logs:Get*",
                "logs:List*",
                "logs:StartQuery",
                "logs:StopQuery",
                "logs:TestMetricFilter",
                "logs:FilterLogEvents"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
    ]
}

Contribute

  • Fork the repository on GitHub.
  • Write a test which shows that the bug was fixed or that the feature works as expected.
    • Use tox command to run all the tests in all locally available python version.
  • Send a pull request and bug the maintainer until it gets merged and published. :).

For more instructions see TESTING.rst.

Helpful Links

How to provide AWS credentials to awslogs

Although, the most straightforward thing to do might be use --aws-access-key-id and --aws-secret-access-key, this will eventually become a pain in the ass.

  • If you only have one AWS account, my personal recommendation would be to configure aws-cli. awslogs will use those credentials if available. If you have multiple AWS profiles managed by aws-cli, just add --profile [PROFILE_NAME] at the end of every awslogs command to use those credentials, or set the AWS_PROFILE env variable.
  • If you don't want to setup aws-cli, I would recommend you to use envdir in order to make AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY available to awslogs.
Owner
Jorge Bastida
Jorge Bastida
A simple language translator with python and google translate api

Language translator with python A simple language translator with python and google translate api Install pip and python 3.9. All the required depende

0 Nov 11, 2021
A python api to get info on covid-19

A python api to get info on covid-19

roof 2 Sep 18, 2022
A Telegram bot to all media and documents files to web link .

FileStreamBot A Telegram bot to all media and documents files to web link . Report a Bug | Request Feature 🍁 About This Bot : This bot will give you

Code X Mania 129 Jan 03, 2023
Discord bot for Ukrfans Discord server

Ukrfans Discord Bot Discord bot for Ukrfans Discord server. 💡 Prerequisites Python ⚙️ Build & Run Create an .env file in the root directory and add t

3 Jun 24, 2022
A discord program that will send a message to nearly every user in a discord server

Discord Mass DM Scrapes users from a discord server to promote/mass dm Report Bug · Request Feature Features Asynchronous Easy to use Free Auto scrape

dropout 56 Jan 02, 2023
Get an SNS alert for High Severity GuardDuty findings

Automation AWS-GuardDuty findings Get an SNS alert for High Severity GuardDuty findings Problem: Getting notified when there is Red finding in AWS Gua

Giten Mitra 4 Nov 18, 2022
API kumpulan doa-doa sesuai al-qur'an dan as-sunnah

API kumpulan doa-doa sesuai al-qur'an dan as-sunnah

Miftah Afina 4 Nov 26, 2022
Unofficial API wrapper for seedr.cc

Seedr API Unofficial API wrapper for seedr.cc Inspired by theabbie's seedr-api Powered by @harp_tech (Telegram) How to use You can install lib via git

Anjana Madu 49 Oct 24, 2022
=>|<= the MsgRoom bot for Windows 96

=|= bot A MsgRoom bot in Python 3 for Windows96.net. The bot joins as =|=, if parameter name_lasts is not true and default_name is =|=. The full

Larry Holst 2 Jun 07, 2022
GUI Pancakeswap V2 and Uniswap V3 trading client (and bot) MOST ADVANCE TRADING BOT SUPPORT WINDOWS LINUX MAC (BUY TOKEN ON LAUNCH)

GUI Pancakeswap 2 and Uniswap 3 SNIPER BOT 🏆 🥇 (MOST ADVANCE TRADING BOT SUPPORT WINDOWS LINUX MAC) (AUTO BUY TOKEN ON LAUNCH AFTER ADD LIQUIDITY) S

HYDRA 16 Dec 22, 2021
A simple Python API wrapper for Cloudflare Stream's API.

python-cloudflare-stream A basic Python API wrapper for working with Cloudflare Stream. Arbington.com started off using Cloudflare Stream. We used the

Arbington 3 Sep 08, 2022
A Python Client for News API

newsapi-python A Python client for the News API. License Provided under MIT License by Matt Lisivick. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRAN

Matt Lisivick 281 Dec 29, 2022
This is a okay that is okay that means none is okay

Owner: Masterolic 🇮🇳 CatUB A Powerful, Smart And Simple Userbot In Telethon. Credits This is A Remix Bot Of Many UserBot. DARKCOBRA FridayUserBot Ja

Masterolic 1 Nov 28, 2021
Community-based extensions for the python-telegram-bot library.

Community-based extensions for the python-telegram-bot library. Table of contents Introduction Installing Getting help Contributing License Introducti

74 Dec 24, 2022
Python script to download WAX transactions

WAXtax Python script to download WAX transactions WAXtax uses the CoinGecko API and the WAX Blockchain History API to download csvs for each account y

SixPM Software 11 Oct 09, 2022
🔮 A usefull set of scripts to dig into your Discord data package.

Discord DataExtractor 🔮 Discord DataExtractor is a set of scripts that allows you to dig into your Discord Data package. Repository guide ☕ Coffee_Ga

3 Dec 29, 2021
Twitter automation tool for growing organic followers.

Tiwoto Tiwoto is a simple python program that automates some kind of behaviors and keep your account active. Create an .env file in this directory and

Mehmetcan Yildiz 6 Sep 22, 2022
Clash of Clans v6.253 private server written in python

cocps Clash of Clans v6.253 private server written in python how2play download server files download Patched APK run Main.py and play Authors Patched

5 Aug 28, 2022
A working bypass for discord gc spamming

IllusionGcSpammer A working bypass for discord gc spamming Installation Run pip install pip install DiscordGcSpammer then your good to go. Usage You c

6 Sep 30, 2022
This is a Python package to create a snowflake identifier similar to Discord's or Twitter's.

snowflake2 Based on falcondai and fenhl's Python snowflake tool, but with documentation and simliarities to Discord. Installation instructions Install

Learnloot 2 Mar 19, 2022