
AWS CloudWatch Logs enables you to centralize the logs from all of your systems, applications, and AWS services that you use, in a single, highly scalable service. You can then easily view them, search them for specific error codes or patterns, filter them based on specific fields, or archive them securely for future analysis.
By default, logs are kept indefinitely and never expire. You can adjust the r
etention policy for each log group, keep indefinite retention, or choose a retention period between one day and 10 years. You can use CloudWatch Logs to store your log data in highly durable storage. The CloudWatch Logs agent makes it easy.
There are two ways to archive the logs:
1. Manual process
2. Automated process
In today’s post, we are going to see both this process.
Prerequisite:
Before starting, follow the below steps to give Cloudwatch logs permission on S3 bucket.
1: Log in to your AWS account.
2: Create an Amazon S3 Bucket with region same as cloud watch logs region.
3: Create an IAM User with Full Access to Amazon S3 and CloudWatch Logs. To learn more about how to create an AWS S3 bucket & create an IAM user read here.
4: Set Permissions on an Amazon S3 Bucket.
a. By default, all Amazon S3 buckets and objects are private. Only the resource owner, the AWS account that created the bucket, can access the bucket and any objects that it contains. However, the resource owner can choose to grant access permissions to other resources and users by writing an access policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "s3:GetBucketAcl",
"Effect": "Allow",
"Resource": "arn:aws:s3:::bucket_name",
"Principal": { "Service": "logs.selected_region.amazonaws.com" }
},
{
"Action": "s3:PutObject" ,
"Effect": "Allow",
"Resource": "arn:aws:s3:::bucket_name/random_string/*",
"Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" } },
"Principal": { "Service": "logs.selected_region.amazonaws.com" }
}
]
}
By setting the above policy inside S3 bucket -> Permissions, Bucket policy -> Bucket Policy Editor, bucket owner allows CloudWatch Logs to export log data to Amazon S3 bucket.
Manual Process:
Step 1: Go to cloud watch -> Log groups -> Select the log group that you want to export -> select Export Data to Amazon S3.



Step 6: Choose the time range & S3 bucket name, For the S3 Bucket prefix, enter the randomly generated string that you specified in the bucket policy. Click Export & you can see logs inside the selected S3 bucket.
Automated Process:
Step 1: Go to AWS Lambda -> Functions.
AWS Lambda is a serverless compute service that runs your code in response to events and automatically manages the underlying compute resources for you. You can use AWS Lambda to extend other AWS services with custom logic or create your own back-end services that operate at AWS scale, performance, and security.
Step 2: Choose to create function -> Choose Author from scratch.
The code you run on AWS Lambda is called a “Lambda function.” After you create your Lambda function it is always ready to run as soon as it is triggered, similar to a formula in a spreadsheet. Each function includes your code as well as some associated configuration information, including the function name and resource requirements. Lambda functions are “stateless,” with no affinity to the underlying infrastructure, so that Lambda can rapidly launch as many copies of the function as needed to scale to the rate of incoming events.
Step 3: Give the function a name. Choose runtime as Node.js 14x & select the permission as “Create a new role with basic Lambda permissions”.
Step 4: Once the lambda function is created. Go to Code and copy-paste the following code.
const AWS = require('aws-sdk')const cloudconfig = {
apiVersion: '2014-03-28',
region: 'selected_region', // replace with your region
}
const cloudwatchlogs = new AWS.CloudWatchLogs(cloudconfig)exports.handler = async (event, context) => {
const params = {
destination: 'bucket_name', // replace with your bucket name
from: new Date().getTime() - 8640000,
logGroupName: 'log-name',
to: new Date().getTime(),
destinationPrefix: 'random_string', // replace with random string used to give permisson on S3 bucket
};
await cloudwatchlogs.createExportTask(params).promise().then((data) => {
console.log(data)
return ({
statusCode: 200,
body: data,
});
}).catch((err) => {
console.error(err)
return ({
statusCode: 501,
body: err,
});
});
}
In the above code, we are creating a new cloudwatch log instance to call create export task.
Parameter description:
i. destination: The name of S3 bucket for the exported log data. The bucket must be in the same AWS region.
ii. destinationPrefix: The prefix used as the start of the key for every object exported. If you don’t specify a value, the default is exportedlogs
.
iii. from: The start time of the range for the request, expressed as the number of milliseconds after Jan 1, 1970, 00:00:00 UTC. Events with a timestamp earlier than this time are not exported.
iv. logGroupName: The name of the log group.
v. logStreamNamePrefix: Export only log streams that match the provided prefix. If you don’t specify a value, no prefix filter is applied. It’s an optional parameter.
vi. taskName: The name of the export task. It’s an optional parameter.
vii. to: The end time of the range for the request, expressed as the number of milliseconds after Jan 1, 1970, 00:00:00 UTC. Events with a timestamp later than this time are not exported.
If you test the above function it will start the export logs task & gives you taskId as a response.
Step 5: Click to “Add Trigger” and choose “Event bridge”.
To run the above function automatically we need to add the trigger event. Amazon EventBridge is a serverless event bus that makes it easier to build event-driven applications.

Choose the rule name & state the description. Schedule expression will act as CRON which will automatically trigger the event on matching expression. We are going to set the 1-day rate which invokes the lambda function every day.
Thanks for reading.
Dear noob2geek.in webmaster, Your posts are always well-received and appreciated.
Medicine information for patients. Buy cialis online cheap Some news about meds. Read information now.
modafinil without prescription
I am truly thankful to the owner of this web site who has shared this fantastic piece of writing at at this place.
medical mall pharmacy
Why would you use a nebulizer ventolin hfa inhaler coupon 2021 – https://www.ventolin.club/
I think the content you share is interesting, but for me there is still something missing, because the things discussed above are not important to talk about today.
Pretty! This has been a really wonderful post. Many thanks for providing these details.
Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated
furosemide overdose torsemide to furosemide conversion globalrph lasix liquid
To the noob2geek.in owner, You always provide great examples and real-world applications.
To the noob2geek.in admin, Keep up the great work!
cheapest generic sildalis
buy antabuse pills
clomid for men for sale
medicine gabapentin 300 mg
fildena tablets
benicar 323
medrol 16 tablet
purchase cipro online
buspar 15mg tablet
clonidine hcl er
where to buy sildalis
viagra sans ordonnance dianeige https://www.sildefran.com/ sildenafil 100mg avis
baclofen buy uk
I do not even understand how I ended up here, but I assumed this publish used to be great
How to lose 5 pounds in a week dapoxetine sildenafil?
This is my first time pay a quick visit at here and i am really happy to read everthing at one place
advair diskus 500 50 mcg coupon
zoloft 125
clonidine 01 mg
I appreciate you sharing this blog post. Thanks Again. Cool.
very informative articles or reviews at this time.
Cool that really helps, thank you.
buy proscar 5mg
where can i buy elimite
buy cheap lisinopril 40mg
indocin 50 mg tablets
Quels sont les couples qui durent cialis avis utilisateur?
budesonide 3 mg tablet
propecia brand
generic flagyl online
very informative articles or reviews at this time.
Dear noob2geek.in admin, Your posts are always well structured and easy to follow.
colchicine pill
I truly appreciate your technique of writing a blog. I added it to my bookmark site list and will
This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!
I appreciate you sharing this blog post. Thanks Again. Cool.
chloroquine purchase
kamagra oral jelly buy online india kamagra chewable tablets buy kamagra jelly in london.
lasix medication over the counter
I very delighted to find this internet site on bing, just what I was searching for as well saved to fav
neurontin 400 mg price
can i buy prozac online
buy levaquin online
neurontin online usa
amitriptyline 10 mg tablet price
paxil prescription
Good post! We will be linking to this particularly great post on our site. Keep up the great writing
cozaar 15 mg
atenolol 100 mg daily
naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.
This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!
Hmm it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to the whole thing. Do you have any tips and hints for beginner blog writers? I’d genuinely appreciate it.
indocin 25 mg capsules
order lexapro
how much is prednisone 10mg
ampicillin purchase
Dear noob2geek.in admin, Thanks for the great post!
dexamethasone cream
celexa pill costs
dapoxetine buy online
albendazole in usa
aurogra 100 uk
feldene 20 mg tablet
buy synthroid australia
baclofen medicine price
propranolol 240 mg
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?
baclofen online uk
arimidex price in usa
mexico pharmacy order online
Dear noob2geek.in owner, Your posts are always well-referenced and credible.
lioresal tablet
sildenafil 100mg price canadian pharmacy
For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.
I just like the helpful information you provide in your articles
reputable canadian online pharmacies
buy clopidogrel
order Stromectol over the counter: How do you set a girl
very informative articles or reviews at this time.
mail order pharmacy
prices generic cialis
I think this post makes sense and really helps me, so far I’m still confused, after reading the posts on this website I understand.
clindamycin 150mg prices
lyrica 200 mg price
mexican online mail order pharmacy
I agree with your point of view, your article has given me a lot of help and benefited me a lot. Thanks. Hope you continue to write such excellent articles.
inderal tab
zestoretic 20 25
tadacip 20mg
Thanks for the feedback! That’s an interesting point. I suppose there are many reasons, internal and external, why we do not accomplish all that we might. Regardless, I am thankful for the Lord’s grace in that. Thanks again!
elimite 5 cream over the counter
benicar 10 mg
strattera 80 mg capsule
can i take 10mg cialis every day – What time of day is sperm count highest
There is definately a lot to find out about this subject. I like all the points you made
Hello noob2geek.in owner, Good to see your posts!
colchicine 500 mg tabs
how much is avodart cost
atenolol 300 mg
I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.
Can impotent man have child Cialis coupons
celebrex prices usa
advair diskus 160 90 mcg
Awesome! Its genuinely remarkable post, I have got much clear idea regarding from this post
ventolin best price
buy elimite cream over the counter
legitimate online pharmacy uk
canadian pharmacies that deliver to the us
triamterene-hctz 37.5-25 mg tb
6mg colchicine
legitimate canadian mail order pharmacy
doxycycline 75 mg capsules
Dear noob2geek.in admin, Your posts are always a great source of knowledge.
plavix online
canadian pharmacy no prescription
To the noob2geek.in owner, Your posts are always a great source of knowledge.
Hello noob2geek.in admin, Your posts are always well received by the community.
Hi noob2geek.in administrator, Your posts are always well-formatted and easy to read.
augmentin 500 125 mg tablet
furosemide 50 mg tablets
Pretty! This has been a really wonderful post. Many thanks for providing these details.
I truly appreciate your technique of writing a blog. I added it to my bookmark site list and will
You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
generic for strattera
www pharmacyonline
canadian pharmacy gabapentin
Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
disulfiram 250 mg buy online
stratera
deltasone 5 mg
cost of synthroid 50 mcg
Good post! We will be linking to this particularly great post on our site. Keep up the great writing
drug effexor 25 mg
generic zoloft online pharmacy
prescription for propecia
Nice post. I learn something totally new and challenging on websites
buy cymbalta 60 mg online
There is definately a lot to find out about this subject. I like all the points you made
Dear noob2geek.in webmaster, Good work!
Hi noob2geek.in administrator, Good work!
canadian pharmacy online cialis
retin a online pharmacy uk
cheapest generic propecia
naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.
synthroid 25 mg coupon
synthroid levothyroxine
buy ciprofloxacin 500mg online
effexor 225
buying strattera online without prescription
proscar cost in us
average cost of prozac
buy tamoxifen aus
strattera 18 mg cost
furosemide cream
online amoxicillin prescription
citalopram 30 mg
kamagra oral jelly price in uae
nolvadex over the counter
allopurinol 300 mg tablets price
strattera cost in mexico
online pharmacy in turkey
gabapentin 600 mg cost
buspar 555
buy zoloft online no rx
Hi noob2geek.in admin, You always provide helpful diagrams and illustrations.
Hi noob2geek.in owner, Your posts are always well-written and easy to understand.
cost of prozac uk
levitra online pharmacy india
clopidogrel 25 mg
To the noob2geek.in owner, You always provide great examples and case studies.
buy misoprostol canada
Hello noob2geek.in webmaster, Thanks for the detailed post!
generic terramycin
buy plaquenil 200mg
Hi noob2geek.in owner, Your posts are always on point.
Hi noob2geek.in admin, Your posts are always on point.
To the noob2geek.in owner, Thanks for the educational content!
buy amoxicillin 500mg without prescription
tizanidine tablets
lexapro 20 mg
Hello noob2geek.in admin, Thanks for the well-researched and well-written post!
Dear noob2geek.in administrator, Thanks for the educational content!
toradol 30
furosemide 25 mg tablet
cephalexin brand name
clonidine uk buy
lasix online india
To the noob2geek.in administrator, You always provide valuable information.
Hi noob2geek.in owner, Thanks for the well-researched and well-written post!
Hi noob2geek.in admin, Your posts are always well-written and easy to understand.
Hello noob2geek.in owner, Your posts are always well-timed and relevant.
Fortunately, there is a new registrar cheap domain names from $0.99
Namecheap exists to help EVERYONE get, make, and achieve more online with less cost, hassle, and headaches. We offer everything you need to get online and thrive, from domains to hosting to security to specialist services and products — all with value built in.
Great prices, world-beating customer support, and extra resources come as standard. ==>> https://zeep.ly/rxViL
Gгeetings! Ꮩery helpful advice within this article!
It is the little changes which will make the most
important changes. Thanks for sharing!