Auto tag AWS resources with Lambda
Automating AWS resource Tagging
Why Tagging resources?
Tagging AWS resources is very important when you want to automate some tasks based on the tags, like you want to install patch automatically based on the tags from SSM association or you want to get a list of resources based on the tags. There are many aspects where tagging the resources will be required.In this blog, I will be showing on automatically adding a tag CreatedBy to the S3 bucket. You can leverage the same logic to other AWS resources.
Architectural design
AWS resources:
- EventBridge
- Lambda
- Trail (CloudTrail)
In Cloud, event plays very important role in automation, Amazon EventBridge is a serverless event bus that makes it easier to build event-driven applications at scale using events generated from your applications, integrated
Software-as-a-Service (SaaS) applications, and AWS services.
Steps:
-
Create Lambda function, lambda is written in python 3.x version, you can find the working code in below link
https://github.com/prasannakumarkn/LambdaFunctions/blob/feature/s3-auto-tagging
- Lambda Role required below permission
- S3 bucket tagging permission
- AWSLambdaBasicExecutionRole (Managed policy)
- Create EventBridge rule with below configuration
Done, so we have configured trigger for lambda and when a new S3 bucket is created, automatically bucket tag will be applied. This tag helps to understand on who created the resources by seeing the tag.
Hope this blog helps in your use case!!! Happing Coding
This blog helped me in setting up automation in my organization, thanks for sharing
ReplyDelete