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-sdk-tracer

v0.0.3

Published

Tracing support for aws-sdk provided with a simple wraper and built-in CLI.

Downloads

2

Readme

aws-sdk-tracer

This is a library intended to be used to instrument the AWS NodeJS SDK by wrapping the library and tracing calls made to the AWS API.

Context

Traces can be collected from a wrapped AWS SDK library (required by dependent) by either injecting a custom AWS.Request class which will parse successful transactions or by providing a custom logger to AWS.config.logger.

Traces are collected in an in-memory catalog which digests transactions into ervice utilization information which can be manually printed and/or retrieved through the wrapper. Additionally, there are built-in exporters which provide means for exporting the collected trace data.

The primary goal of this tracing is to facilitate developer knowledge of AWS service actions and resources used during development in order to generate tightly scoped policies for components deployed into an AWS account without the need to parse AWS CloudTrail logs for an account potentially used by several engineers. This can be done by specifying the filesystem exporter when wrapping the AWS SDK. This exporter will maintain a temporary file with data regarding the utilization of the SDK during runtime and between executions. At any point this file can be provided to a command line script gen-policy [<path>] (where <path> is the optional path to the exported file which, by default, is located at /tmp/aws-sdk-tracer.json). The script will attempt to parse the contents and generate an AWS Policy Document with statements pertaining to how each service is used.

Example:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ECSUtilization",
      "Action": [
        "ecs:listClusters",
        "ecs:listTasks"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:ecs:us-east-1:931703384005:cluster/dlp",
        "arn:aws:ecs:us-east-1:931703384005:cluster/devcoreinfra"
      ]
    }
  ]
}

Note: Policies generated by this library are very simplistic and not necessarily intended to be used as-is. Rather, the expectation is that these policy documents can be used as a jump-off point for determining how to scope the policies for your component once deployed. All statements generated will in effect "Allow" the actions which were traced.

Usage

Install the package using NPM as you would:

npm install --save aws-sdk-tracer

The quickest way to get started is to simply load the library and aws-sdk together:

const {AWS, wrapper} = require('aws-sdk-tracer').wrapAWSSDK(require('aws-sdk')); 

// ... after creating and using AWS services ...

wrapper.printUtilization();

This will utilize the default tracer type which will replace the AWS.Request class.

Since no exporters were specified, all trace data is in memory so wrapper.printUtilization() is used to print the utilization data.

The wrapper also supports options for console logging trace/AWSLogger events for each request sent as well as specifying various exporters.

const AWSSDKTracer = require('aws-sdk-tracer');

const wrapperOpts = {
    logger: console,
    exporters: [
        'filesystem',
    ]
};

const {AWS, wrapper} = AWSSDKTracer.wrapAWSSDK(require('aws-sdk'), wrapperOpts); 

Optionally, you can set the tracer option to "Logger" which, instead of injecting the traced AWS.Request class will provide a custom logger to the AWS SDK config.

const AWSSDKTracer = require('../');

const wrapperOpts = {
    logger: console,
    tracer: 'Logger',
    exporters: [
        'filesystem',
        'http'
    ]
};

const {AWS, wrapper} = AWSSDKTracer.wrapAWSSDK(require('aws-sdk'), wrapperOpts); 

Note: In either case, you do not need to use the AWS SDK as returned by the wrapper as the library itself is effectively wrapped.

const AWSSDKTracer = require('aws-sdk-tracer');
const AWS = require('aws-sdk');

const wrapperOpts = {
    logger: console,
    exporters: [
        'filesystem',
    ]
};

AWSSDKTracer.wrapAWSSDK(AWS, wrapperOpts); 

const ECS = new AWS.ECS();

// ... etc.

Warning: The wrapper will only wrap the AWS-SDK once if it is not already wrapped with either the Logger or Request options. If for some reason you want to change the type, the library must first be unwrapped then wrapped again.

Example:

const AWSSDKTracer = require('../');

const wrapperOpts = {
    logger: console,
    tracer: 'Logger',
    exporters: [
        'filesystem',
        'http'
    ]
};

const {AWS, wrapper} = AWSSDKTracer.wrapAWSSDK(require('aws-sdk'), wrapperOpts); 

try{
  wrapper.wrap(AWS); // throws error
} catch() {
  wrapper.unwrap(AWS);
  wrapper.setTracer('Request');
  wrapper.wrap(AWS); // good
}

Todo

There is a lot more that can be done; this is only touching the surface.

  • finish implementation of HTTP exporter
    • the goal of this exporter would be for private utilization telemetry data
  • better/more tests
  • better options and configurability of wrapper and other components

TypeDocs

TypeDocs can be found onthe associated GitHub IO: https://ccampanale.github.io/aws-sdk-tracer/