visit
If you work with serverless projects, as you might be aware that a serverless project can end up with hundreds of Lambda functions which definitely increases the complexity of your application, good new is that AWS Resource Groups recently announced its support for more resource types, especially for groups based on an AWS CloudFormation stack.
By using Resource Groups, you might find it very useful to act on all corresponding resources as group rather than move around from one service to another.In this article, I will be building a serverless restful api project using Serverless Framework and create a resource group that contains a collection of related AWS services for our api project.
npm install -g serverless
sls create --template aws-nodejs --path myapp
The directory that is created includes two files — handler.js is the Lambda function, the serverless.yml file contains the configurations of the backend, add following config to serverless.yml:
service: myapp
provider:
name: aws
runtime: nodejs8.10
region: ap-southeast-2
tags:
serverless: myapp
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
Let’s update our handler.js, create a lambda function to handle api gateway request:
'use strict';
module.exports.hello = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
sls deploy --stage dev
Let’s open the AWS Resource Groups console, on the navigation pane, under Resource Groups, choose Create Resource Group.
Select CloudFormation stack based, then choose the CloudFormation stack, in this example, we have myapp-dev stack just deployed,
click View group resources button to see all the related services included the stack.
In Group details, type the group name and description.
Everything is configured, choose Create group. We can go to Saved resource groups to view resource group we just created.
Navigating to the group resource, we can see the our serverless project includes S3, ApiGateway RestApi, lambda, CloudWatch Logs and Iam role resources.
Let’s open , choose Resource Groups in the left navigation pane under Operations Management, We can see all the event log data from CloudTrail.
That’s all about it! Thanks for reading, I hope you have found this article useful, please give me a follow if you’d like to see more in future!