Skip to content

Save AWS API call metrics to CloudWatch Metrics via Cloud Trail events

License

Notifications You must be signed in to change notification settings

evalphobia/serverless-aws-api-metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-aws-api-metrics

GoDoc License: MIT 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

About

Save AWS API call metrics to CloudWatch Metrics via Cloud Trail events

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published