serverless-aws-api-metrics

command module
v0.0.0-...-da422b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 12 Imported by: 0

README

serverless-aws-api-metrics

GoDoc Release Build Status Codecov Coverage Go Report Card Code Climate BCH compliance

serverless-aws-api-metrics fetchs AWS API calls from CloudTrail events log and save the events count in sec by sampling into CloudWatch Custom Metrics, powered by AWS Lambda.

What's for?

Some AWS API is not billing target but has some quotas. For example, SNS::GetEndpointAttributes has default soft-limit. It's 3000tps in us-east-1 but only 30tps in eu-west-2 and eu-west-3.

Some API call can retrive through CroudTrail events so I want to monitor them. https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html

Download

Download serverless-aws-api-metrics by command below.

$ git clone https://github.com/evalphobia/serverless-aws-api-metrics
$ cd serverless-aws-api-metrics
$ make init

Config

serverless.yml

Change environment variables below,

$ vim serverless.yml

------------

provider:
  name: aws
  region: ap-northeast-1  # <- Change to your target region.


...

functions:
  sns:
    handler: bin/serverless
    # tags:
    #   env: prod
    memorySize: 128
    timeout: 290
    environment:
      # Change to your target AWS services.
      METRIC_EVENT_GROUP: 'SNS'
      # Change to your target CloudTrail event name.
      METRIC_EVENT_NAME: 'GetEndpointAttributes,SetEndpointAttributes'
    events:
      - schedule: cron(*/5 * * * ? *)  # exec every 5min

Environment variables

Name Description Default
METRIC_EVENT_GROUP Metrics namespace and prefix used in CloudWatch Metrics. This should be service name. (e.g. ses, sns, dynamodb) -
METRIC_EVENT_NAME Event name on CloudTrail. Put multiple names with comma. (e.g. GetEndpointAttributes,SetEndpointAttributes, CreateNetworkInterface, PutBucketPolicy) -
METRIC_TARGET_SECOND The second of time in minute for sampling. 31 (= YYYY-MM-DD hh:mm:31)

Deploy

$ AWS_ACCESS_KEY_ID=<...> AWS_SECRET_ACCESS_KEY=<...> make deploy

Check Log

$ AWS_ACCESS_KEY_ID=<...> AWS_SECRET_ACCESS_KEY=<...> sls logs -f <function name> -t

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL