npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-logs-sink

v1.0.3

Published

Stream logs to Amazon CloudWatch logs

Downloads

200

Readme

aws-logs-sink

Stream logs to AWS CloudWatch Logs.

Either pipe your log lines to stdin from the CLI, or use this module programmatically in NodeJS––it exposes a NodeJS writable stream.

Can't I just use the AWS CLI/SDK?

Yes, but streaming logs to CloudWatch Logs is slightly less trivial than you might think, because each successive putLogEvents call must include the log stream's nextSequenceToken from the previous putLogEvents call. This module is a small wrapper around the JavaScript AWS SDK (V3) to make streaming logs easy.

CLI usage

Install globally:

npm install -g aws-logs-sink

Provide the log group name and stream name as arguments, and pipe to stdin:

echo "This is a test" | aws-logs-sink <log-group-name> <log-stream-name>

Of course a long running stream works too:

while true; do date; sleep 1; done | aws-logs-sink <log-group-name> <log-stream-name>

The log group and stream will be created if they don't exist. If the log stream already exists, its next sequence token will be queried, in order to be able to append to the stream.

CLI options:

| Option | Description | | ------------------------ | ----------------------------------------------------------------------------- | | -f, --flush-interval | Flush to CloudWatch every X seconds (default: 1) | | --tee | Also print all input to stdout | | --eol | Line termination character(s) (default: \n on Mac/Linux, \r\n on Windows) | | --profile | AWS profile to use. Setting environment variable AWS_PROFILE works too | | --region | AWS region to use. Setting environment variable AWS_REGION works too |

Programmatic usage

Install locally:

npm install aws-logs-sink
import awsLogsSink from "aws-logs-sink";

// awsLogsSink is a function that returns a NodeJS writable stream:
const writable = awsLogsSink({
  logGroupName: "<log-group-name>",
  logStreamName: "<log-stream-name>",
  flushInterval: 1, // optional, see table above
  tee: false, // optional, see table above
  eol: "\n", // optional, see table above
  profile: "default", // optional, see table above
  region: "eu-west-1", // optional, see table above
  client: new CloudWatchLogsClient({}), // optional, will be created if not provided
});

writable.write("Hello, world!");

// Or more fancy with a pipeline:

import * as stream from "stream";

const readable = new stream.Readable({ read: () => {} });
readable.push("Hello, world! From pipeline");
readable.push(null);

stream.pipeline(readable, writable, (err) => {
  err ? console.error(err) : console.log("Done writing to CloudWatch");
});

Required AWS permissions

| Permission | Required | | ------------------------- | --------------------------------------------------------------------------- | | logs:CreateLogGroup | Yes | | logs:CreateLogStream | Yes | | logs:PutLogEvents | Yes | | logs:DescribeLogStreams | Only if writing to an existing log stream, to query its next sequence token |