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.
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 serverless-aws-api-metrics by command below.
$ git clone https://github.com/evalphobia/serverless-aws-api-metrics
$ cd serverless-aws-api-metrics
$ make init
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
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 ) |
$ AWS_ACCESS_KEY_ID=<...> AWS_SECRET_ACCESS_KEY=<...> make deploy
$ AWS_ACCESS_KEY_ID=<...> AWS_SECRET_ACCESS_KEY=<...> sls logs -f <function name> -t