Organize your Lambda functions into separate services

Sergei Khazov
3 min readJul 3, 2018

--

When I started my first complex application with full end-to-end serverless approach on AWS ecosystem I faced into the issue with continuously growing number of lambda functions living independently from each other. It become extremely hard to navigate between function and determine which lambda function related to certain service. I started to think, how I can solve this issue, so I can monitor my application at the end, quickly navigate through the functions and categorize lambda functions into different services. So I came up with this approach.

For developing serverless application I’m using serverless framework It has tones of useful plugins and ready out of the box features. For having set of lambda functions organized in one application service or some kind of abstracted entity I came up with tagging approach. Lots of AWS services supports tags, same as AWS Lambda functions. To apply this approach there no need to install any plugins for serverless framework, it supported out of the box. Here’s the example for my serverless.yml template:

Whole Serverless service tagging example

In example above I used stackTags provider attribute. stackTags attributes adds list of tags to the whole CloudFormation stack. It means that these tags will be applied for all resources created by CloudFormation stack(only resources for which AWS CloudFormation supports tagging)

In case if you need to apply tags only for specific lambda functions, you can specify those tags under tags property in function declaration section in serverless.yml file. Here’s an example:

Function specific tags example

After the application is deployed, I was able to search my lambda function by the tag name:

Tags search options

When I need to search some lambda function by service name, I select SERVICE_NAME tag and select CognitoUser service name as a tag value and get only 6 function out of 127, which are related to CognitoUser service.

Result Filter by tag CognitoUser

As the resolute of applying this tagging strategy it helps me a lot to quickly navigate between different services, identify and categorize those resources.

As one of the additional benefits of apply tags for serverless application, it gives you ability to query your resources through AWS resource groups tagging API. Here’s the example how you can get all your resources regarding the tag SERVICE_NAME: CognitoUser

Get resources by tag using AWS CLI

Also I reached out AWS support team regarding the feature of building AWS CloudWatch dashboards based on resource tags. AWS support team replayed that CloudWatch service team is currently working on feature, that will allow developers build CloudWatch dashboard metrics for lambdas based on tags. So keeping eyes on updates and looking forward for new features.

--

--

Sergei Khazov

Cloud Engineer. Solution Architect. Full Stack Web-Developer. Excited about serverless approach.