Clever/aws-sdk-go-counter

Name: aws-sdk-go-counter

Owner: Clever

Description: Wrapper around aws-sdk-go that counts API requests made to AWS.

Forked from: aws/aws-sdk-go

Created: 2017-09-06 00:25:17.0

Updated: 2018-03-29 02:55:46.0

Pushed: 2018-02-21 16:52:56.0

Homepage:

Size: 50399

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

aws-sdk-go-counter

Wrapper around aws-sdk-go that counts API requests made to AWS.

Motivation

AWS APIs have rate limits, so monitoring the rate at which code is using different AWS APIs is useful.

Example usage

Take normal aws-sdk-go client usage like this:

age main

rt (
"log"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"


 main() {
sess := session.New()
svc := s3.New(sess)
_, err := svc.ListBuckets(nil)
if err != nil {
    log.Fatal(err)
}

and wrap it

age main

rt (
"fmt"
"log"

"github.com/Clever/aws-sdk-go-counter/counter/s3counter"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"


 main() {
sess := session.New()
svc := s3counter.New(s3.New(sess))
_, err := svc.ListBuckets(nil)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%v\n", svc.Counters())

Output:

ListBuckets:1]

You could also print the values periodically in the background e.g.

go func() {
    ticker := time.NewTicker(10 * time.Second)
    for _ = range ticker.C {
        fmt.Printf("%v\n", svc.Counters())
    }
}()

At Clever you could also route logs to metrics backends like SignalFX, e.g. https://github.com/Clever/workflow-manager/pull/87.

Developing

This repo uses a modified version of aws-sdk-go's codegen to produce the code in the counter/ directory. Run make deps + make all in the the counter directory to generate the counters.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.