npm

s3st

1.1.0 • Public • Published

s3st

A command line utility that allows you to stream data from multiple S3 objects directly into your terminal.

npm version CircleCI JavaScript Style Guide

Demo!

Demo image terminal

See the FULL demo on asciinema

Rationale

This utility is particularly useful when you are storing data in S3 and you want to easily process the content of your S3 objects from your command line, for instance if you are storing your CloudTrail logs in an S3 buckets and you want to grep over them you can do something like this:

s3st mybucket AWSLogs/123456789/CloudTrail/eu-west-1/2019/01/17/ | jq . | grep "lambda"

By default the command line will be able to decompress most compressed files in realtime (gzip, brotli and deflate).

Install

There are several ways to install s3st:

Install global with NPM

(Requires Node v10+):

npm i -g s3st

Precompiled binaries

Alternatively you can download one of the pre-compiled binaries for linux, windows, mac or alpine from the Releases page.

These binaries do not require you to have Node installed.

With npx (use without install)

npx s3st some-s3-bucket

Usage

Usage: s3st [options] <bucket> [prefix]
 
Options:
  -v, --version            output the version number
  -D, --do-not-decompress  Do not try to decompress files automatically (gzip, deflate, brotli)
  -h, --help               output usage information

bucket represents the name of the bucket to iterate over prefix is an optional argument that you can pass to select a subset of object that match the given prefix.

Automatic Decompression

The command will automatically try to decompress compressed files based on their extension, as per the following mapping:

  • .gz or .gzip: decompress using gzip
  • .zz or .deflate: decompress using deflate
  • .br or .brotli: decompress using brotli (available only if using Node v11.7+)

If you want to disable this option you can specify the flag --do-not-decompress

AWS Authentication

The tool will assume you have the proper environment variables or configuration files properly set as per the AWS CLI documentation in order to authenticate requests to AWS.

Programmatic usage

This package can also be used programmatically as per the following example:

'use strict'
 
const createS3stStream = require('s3st')
const AWS = require('aws-sdk')
 
// creates an s3 client using the AWS SDK
const s3 = new AWS.S3()
 
const stream = createS3stStream(s3, 'mybucket', 'some-prefix')
 
stream.pipe(process.stdout) // attach the stream to standard output

createS3stStream exposes accepts the following arguments:

  • s3: an s3 client instance from the AWS SDK or a compatible implementation
  • bucketName: the name of the bucket
  • prefix (optional): an object prefix to filter objects in the bucket
  • transform (optional): a function that allows you to transform the content of objects as they get streamed (useful for instance for decompression or decryption).

Transform function

If you want to provide a custom transform function, it should respect the following signature.

Arguments

  • key (string): the name of the current object (object key)

Return value

  • a Transform stream that manipulates the object

If you want to use the default decompression implementation available by the default in the command line client, you can import that from s3st/src/transformers/decompress.

Data Transfer costs

If you are using this tool to stream large amount of data be aware that this might have an impact on your data transfer costs. In such cases, using an alternative approach like S3 Select, could be a way to save on cost.

Make sure you are aware of alternatives and that you make careful costs considerations before running any heavy workload in the cloud.

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

You can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.

License

Licensed under MIT License. © Luciano Mammino.

Package Sidebar

Install

npm i s3st

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

10.3 kB

Total Files

6

Last publish

Collaborators

  • lmammino