Organize your Lambda functions into separate services

Sergei Khazov
Jul 3, 2018 · 3 min read

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade