-
Create an S3 Bucket (To Store CloudWatch Logs)
- Navigate to the Amazon S3 Dashboard.
- Click on "Create bucket."
- Once the bucket is created, open it and go to the
Permissionstab. - Grant CloudWatch write access to the bucket by setting up a
bucket policy. - Click on the
Editbutton forBucket Policyand paste the following JSON policy
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "logs.<YOUR_REGION>.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>" }, { "Effect": "Allow", "Principal": { "Service": "logs.<YOUR_REGION>.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" } } } ] }- Finally, Choose
Save Changes.
-
Create IAM Role (To be used for Lambda automation)
- Navigate to your AWS IAM Dashboard.
- Switch to the
Rolestab and click on theCreate rolebutton. - Under Select type of trusted entity, choose
AWS serviceand underUse case, selectLambdaand click on Next. - Search for
AmazonS3FullAccess,CloudWatchLogsFullAccess, andCloudWatchEventsFullAccesspolicies, and select each of them. - Set the Role Name to
Export-RDS-CloudWatch-To-S3-Lambda-Roleand click onCreate role.
-
Lambda (Function to automate CloudWatch Logs export to S3)
- Navigate to the AWS Lambda Dashboard.
- Click on the
Functionstab and then clickCreate function. - Choose
Author from Scratch. - Set the Function name to
Export-RDS-CloudWatch-Logs-To-S3. - Under
Runtime,selectPython 3.x. - Under
Permissions,chooseUse an existing roleand select the IAM role created in the previous step(Export-RDS-CloudWatch-To-S3-Lambda-Role). - Click on
Create Functionand go to the Code view. Paste the contents of the script filecw-logs-to-s3.pyinto the code editor. - Set the
scrap_intervaltime in minutes within the script. - Then
Deploythe function. - In the
Configurationtab, selectGeneral Configurationand click theEditbutton to change the timeout to10 minutes. - Save the configuration.
-
Set automation to run this lambda function
- Go to your
CloudWatch dashboard. - Go to the
Events ⇒ Rules. - Click on
Create Rule: set rule namelambda-exec-rule. - Under Rule type, select
Schedule. Then clickcontinue to create rule. - Under Schedule pattern, select
A schedule that runs at a regular rate, such as every 10 minutes.Set the rate expression previously you mention in above script. Then click Next. - Choose target type as
AWS service. Under Target, select Lambda Function. - Under Function, select the function we have created in the previous step
Export-RDS-CloudWatch-Logs-To-S3 - Finally, Choose Review and create.
- Go to your
-
Adding dependency module in Layers
To utilize Python's requests module in a Lambda function, you must add it as a layer. Follow these steps:
- follow below steps to create dependencies zip file in your local machine:
mkdir python cd python pip install --target . requests zip -r dependencies.zip ../python
-
Upload your zip file:
- Navigate to
AWS Lambda > Additional Resources > Layers. - Click on
Create Layer. - Under
Namesection enter your layer name. - Choose
Upload a .zip fileand upload yourdependencies.zipfile. - Select compatible architecture and runtimes.
- Click the
Createbutton.
- Navigate to
-
Lambda (Function to automate export S3 Logs to Atatus)
- Switch to AWS Lambda Dashboard.
- Click on the Functions and then click on the Create function button.
- Keep
Author for Scratchselected. - Set Function name:
Export-S3-Logs-To-Atatus - Under
Runtime, select Python 3.x. - Click on
Create Functionand navigate to the Code view. Next, copy the script files3-logs-to-atatus.pyand paste it into the code base. - Then
Deploythe function.
-
Add permissions for Lambda function(Export-S3-Logs-To-Atatus) role
- Go to function
Configurationsand selectPermissionsfrom the left sidebar. - Click on the
Role name link, it will take us to AWS IAM page. - click on the
Add permissionsbutton and selectAttach policiesfrom the drop down list. - Search for
AmazonS3FullAccess,AmazonS3ObjectLambdaExecutionRolePolicy,AmazonS3OutpostsFullAccess, andAmazonS3ReadOnlyAccesspolicies, and select each of them. - Click the
Add Permissionbutton.
- Go to function
-
Adding triggers(S3 Bucket) in Lambda function
- Navigate to
AWS Lambdafunction (Export-S3-Logs-To-Atatus) - Click on the
+ Add triggerbutton from the Lambda console. - Select
s3source underTrigger configuration. - Select your
Bucket Name. - Under
Event Type. ChooseAll object create events. - Check acknowledge and click on
Addbutton.
- Navigate to
-
Add dependency module to your Lambda function
- Navigate to your Lambda function(Export-S3-Logs-To-Atatus).
- Locate the
Layerssection underCodetab. - Click the
Add a layerbutton. - Select
Custom layers, choose your custom layer and version from the drop-down menu. - Click the
Addbutton.
-
Now you will get logs into Atatus Dashboard
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|