Process Serverless CloudFormation Stack Output

July 1, 2017
•
308 words

When you use a serverless environment for your service (and you should!), chances are high you might be using the Serverless framework and may end up in a situation like me with the need to process the AWS CloudFormation Stack Output after deploying the service.

Serverless uses CloudFormation to describe the AWS Stack that is deployed. Thanks to this you can just extend the existing Serverless features with custom resources and basically everything Amazon supports in CloudFormation.

With the serverless-stack-output plugin you can easily process your CloudFormation Stack Output with a custom JavaScript function, or save it in a TOML/YAML/JSON configuration file.

Configuration

Just install the serverless-stack-output plugin using npm or yarn and extend your serverless.yml configuration with the needed information:

Function

The plugin can call a custom JavaScript function after the Stack is deployed and will pass a data object with the Stack Output. To configure a function, use the handle configuration like shown in the example above and create a scripts/output.js file with the following content:

Storage

You can choose to write all Stack Outputs in a configuration file with the file property. The plugin already supports the JSON, YAML, and TOML formats! Just use the file extension matching the format and the plugin will take care of the rest.

It should not be that hard to extend the current formats with a custom one, just have a look at the src/file.js implementation on GitHub …

AWS Lambda functions together with an Amazon Kinesis Stream offer a great way to process continuous information. I created an example project called Serverless Analytics to demonstrate this. You can use this as the starting point to create your very own Google Analytics clone and run it serverless and hopefully maintenance-free on Amazon.

Since a few days, Amazon provides a native way to enable Auto Scaling for DynamoDB tables! Luckily the settings can be configured using CloudFormation templates, and so I wrote a plugin for serverless to easily configure Auto Scaling without having to write the whole CloudFormation configuration.

Have you ever wondered how to process messages from SQS without maintaining infrastructure? Amazon Web Services perfectly support SNS as a trigger for AWS Lambda functions, but with SQS you have to find a custom solution. This tutorial will show an experimental setup using Serverless to read messages from an SQS queue and build auto-scaling worker processes.