Introduction:
In the realm of cloud computing, effective log management is essential. Amazon CloudWatch Logs offers centralized log storage, while AWS Lambda provides serverless computing capabilities. Combining these services enables the automated export of logs to Amazon S3, enhancing data durability and simplifying log management workflows. In this guide, we'll walk through setting up an AWS Lambda function to streamline the process of exporting CloudWatch Logs to an S3 bucket, offering a scalable and efficient solution for organizations seeking improved log data management in the AWS ecosystem.
GitHub Repo: https://github.com/saadkhan024/Cloudwatchlogs-to-S3bucket
Creating a Lambda function.
We need to create a lambda function which will invoke with Cloudawatch
You can select create new role as i am doing for testing purpose.
We will write some dummy function to test the case.
This is my Test function code
You can see that after executing it run successfully.
For checking the logs has been created or not, go to CloudWatch and check on Logs group.
Log has been generated.
For sending the logs from cloudwatch to s3 we will require IAM role.
Creating and IAM role.
and we will select the given policy and edit the trust policy.
We will setup the lambda function with attaching the IAM role which we have created.
We need to change some default configuration time to 15 min of highest.
Now we have to change the lambda function with our customized code and deploy.
you can find the code in my github repo.
Creating an S3 bucket.
Go to search bar and type S3 and click on create and put the info.
We will edit the policy under s3 with our inline policy you can find the same on github repo.
After deploying the script you can see that logs has been generated.
Thank You...