Skip to content
Samuel Overloop edited this page Aug 14, 2019 · 10 revisions

During development and testing stage of serverless solutions, it is paramount to keep the number of utilised resources and their costs under control. Due to the scaling model of a serverless architecture, it happens that the number of resources increases uncontrolled, due, for example, to a software bug. Default AWS monitoring is more often than not insufficient, and precious time is lost before the problem is noticed, diagnosed and remedied.

To solve this problem we have developed Serverless Cost Control (SCC). SCC captures metrics for a real-time reflection of the serverless costs and adds anomaly detection to your serverless resources on which one can configure alerts. SCC can take automatic action when a threshold is reached, e.g. throttling of a lambda function.

SCC gives an almost immediate insight in the serverless costs you are incurring as opposed to AWS Billing which can take up to 24hrs. The costs in the graph below are what you would pay if the current load were maintained for a month.

Estimated Charges

With SCC you can also have an overview of your exact serverless costs (free tier not included) month by month.

Monthly Cost

Configuration

Stack

Configuration happens in the form of Cloudformation Parameters:

  • MetricNameSpace (default: Cloudway/Serverless/Monitoring)
  • Environment (default: dev)
  • ApplicationName (default: cloudway-scc)
  • MonitorEmail: will receive alerts and throttle notifications

By default all serverless resources (Lambda, DynamoDB, Aurora) will be monitored. You can specify which resources to exclude and include using tags. By default the resources created by SCC are excluded.

  • IncludeTags: if provided, only resources with given tags with value "true" will be included (comma separated list).
  • ExcludeTags: exclude resources with given tag(s)

Individual resources

Two extra tags can be used for further configuring single serverless resources:

  • scc-cost-limit: specifies the threshold at which an alert will be issued (default: 10)
  • scc-actionable: specifies whether a resource may be throttled automatically by SCC (default: false)

Deployment

These steps are for a manual deployment to your stack. In the future, an AWS Marketplace solution will be made available.

# Clone repository
$ git clone git@github.com:becloudway/aws-serverless-cost-control.git

# Install dependencies
$ npm install

# Build SCC
$ npm run build

# Package build
$ npm run package

# Upload build artifacts to S3 (public-read)
$ aws s3 cp s3://my-deployment-bucket/build ./build/functions.zip

# Deploy monitoring stack to your AWS account
$ aws cloudformation deploy --template-file cloudformation/monitoring-stack.yaml --stack-name STACK_NAME --profile AWS_PROFILE --region AWS_REGION --parameter-overrides PARAMETER_OVERRIDES --capabilities=CAPABILITY_NAMED_IA
Clone this wiki locally