Skip to main content

AWSCLI CloudWatch Logs plugin

Project description

This awscli plugin provides the pull and push commands to access AWS CloudWatch Logs service.

The awscli-cwlogs package works on Python versions:

  • 2.6.5 and greater

  • 2.7.x and greater

  • 3.3.x and greater

Installation

The easiest way to install awscli-cwlogs is to use pip:

$ pip install awscli-cwlogs

or, if you are not installing in a virtualenv:

$ sudo pip install awscli-cwlogs

If you have the awscli-cwlogs installed and want to upgrade to the latest version you can run:

$ pip install --upgrade awscli-cwlogs

This will install the awscli-cwlogs package as well as all dependencies, including awscli.

Getting Started

Before using awscli-cwlogs plugin, you need to configure awscli first. As of 7/17/2014, CloudWatch Logs service is only available in us-east-1 so you cannot use these commands for other regions.

Once that’s done, to enable awscli-cwlogs, you can run:

$ aws configure set plugins.cwlogs cwlogs

The above command adds below section to your aws config file:

[plugins]
cwlogs = cwlogs

To verify if awscli-cwlogs plugin is installed and configured properly, you can run:

$ aws logs help

You will see the pull and push commands from available commands, otherwise it means the cwlogs plugin is not registered properly.

If you see ImportError: No module named cwlogs error, it means the cwlogs plugin is registered in config file, but the plugin is not installed.

Examples

Push command

You can use aws logs push help to check supported options. The push command is used by CloudWatch Logs agent, check the CloudWatch Logs Agent Reference if you want to keep the push command running.

  1. Uploading a single log event to CloudWatch Logs service. The log group and log stream get created automatically if they don’t exist.

echo "Hello World" | aws logs push --log-group-name MyLogGroup --log-stream-name MyLogStream
  1. The following push command pushes log events from a syslog file to log stream which is specified by /var/log/syslog and myhost1 and exits after pushing all log events. This command doesn’t push the incremental log events. To achieve that, use tail -f file | aws logs push ....

cat /var/log/kernel.log | aws logs push --log-group-name /var/log/syslog --log-stream-name myhost1 --datetime-format '%b %d %H:%M:%S' --time-zone LOCAL --encoding ascii
  1. The following push command pushes log events from multiple files based on configuration file. The initial_position determines where to start if the state of file is not available.

aws logs push --config-file push.cfg
[general]
state_file = push-state
[logstream-messages]
datetime_format = %b %d %H:%M:%S
time_zone = LOCAL
file = /var/log/messages
file_fingerprint_lines = 1
log_group_name = /var/log/messages
log_stream_name = {hostname}
initial_position = start_of_file
encoding = utf_8
buffer_duration = 5000
[logstream-system.log]
datetime_format = %b %d %H:%M:%S
time_zone = UTC
file = /var/log/system.log
file_fingerprint_lines = 1-3
log_group_name = /var/log/system.log
log_stream_name = {hostname}
initial_position = end_of_file
encoding = ascii
buffer_duration = 10000

Pull command

You can use aws logs pull help to check supported options.

  1. The following pull command pulls log events starting at 2014-01-23T00:00:00Z from one log stream which is specified by website1/access_log and webhost-001 and exits after pulling all log events.

aws logs pull --log-group-name website1/access_log --log-stream-name webhost-001 --start-time 2014-01-23T00:00:00Z
  1. When invoked with the --end-time option, the following pull command pulls all log events between 2014-01-23T00:00:00Z (inclusive) and 2014-01-23T01:00:00Z (not inclusive).

aws logs pull --log-group-name website1/access_log --log-stream-name webhost-001 --start-time 2014-01-23T00:00:00Z --end-time 2014-01-23T01:00:00Z
  1. When invoked with the --follow option, the following pull command does not exit after pulling all log events, but polls continuously for new log events.

aws logs pull --log-group-name website1/access_log --log-stream-name webhost-001 --start-time 2014-01-23T00:00:00Z --follow
  1. When invoked with the --output-format option, the following pull command only outputs the message field. By default, the output format is "{timestamp} {message}". Ingestion time can be included with "{timestamp} {ingestionTime} {message}".

aws logs pull --log-group-name website1/access_log --log-stream-name webhost-001 --start-time 2014-01-23T00:00:00Z --output-format "{message}"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awscli-cwlogs-1.3.3.tar.gz (32.5 kB view details)

Uploaded Source

File details

Details for the file awscli-cwlogs-1.3.3.tar.gz.

File metadata

  • Download URL: awscli-cwlogs-1.3.3.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for awscli-cwlogs-1.3.3.tar.gz
Algorithm Hash digest
SHA256 a398bb8bcaffa8496198d6d12ea5f1eb672853d56a8291b501d998b3e5115781
MD5 9d1f901b78935bb2d96f87be8030f6d5
BLAKE2b-256 07e187b15093df8ea80d33edf0f1dedfb95d07117423c8372b4598dd70ab65dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page