From c159168e74cb1bc7974e1a8e8930ae14943a2afa Mon Sep 17 00:00:00 2001 From: Suthagar23 Date: Fri, 7 Jul 2017 18:03:41 +0530 Subject: [PATCH 1/2] CloudWatchLog Implementation --- cloudwatchlogs.js | 55 ++++++++++++++++++++++++++++++++++++++++ cloudwatchlogs_filter.js | 27 ++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 cloudwatchlogs.js create mode 100644 cloudwatchlogs_filter.js diff --git a/cloudwatchlogs.js b/cloudwatchlogs.js new file mode 100644 index 0000000..9047649 --- /dev/null +++ b/cloudwatchlogs.js @@ -0,0 +1,55 @@ +/* + * Copyright 2013. Amazon Web Services, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +**/ + +// Load the SDK and UUID +var AWS = require('aws-sdk'); +var uuid = require('node-uuid'); + +AWS.config.loadFromPath('config.json'); + +// Create an CloudWatchLog client +var cloudwatchlogs = new AWS.CloudWatchLogs(); + +var params = { + limit: 40 +}; +cloudwatchlogs.describeLogGroups(params, function(err, data) { + if (err) console.log(err, err.stack); // an error occurred + else console.log(data); // successful response +}); + + +var params = { + logGroupName: 'API-Gateway-Execution-Logs_9upfn6zpoe/Sample2', + logStreamName: '4c56ff4ce4aaf9573aa5dff913df997a', + limit: 100, + startFromHead: true || false +}; +cloudwatchlogs.getLogEvents(params, function(err, data) { + if (err) console.log(err, err.stack); // an error occurred + else console.log(data); // successful response +}); + + +var params = { + logGroupName: 'API-Gateway-Execution-Logs_9upfn6zpoe/Sample2', + descending: true || false, + limit: 50 +}; +cloudwatchlogs.describeLogStreams(params, function(err, data) { + if (err) console.log(err, err.stack); // an error occurred + else console.log(data); // successful response +}); diff --git a/cloudwatchlogs_filter.js b/cloudwatchlogs_filter.js new file mode 100644 index 0000000..01055b9 --- /dev/null +++ b/cloudwatchlogs_filter.js @@ -0,0 +1,27 @@ +// Load the SDK and UUID +var AWS = require('aws-sdk'); +var uuid = require('node-uuid'); + +AWS.config.loadFromPath('config.json'); + +// Create an CloudWatchLog client +var cloudwatchlogs = new AWS.CloudWatchLogs(); + + +var params = { + logGroupName: 'API-Gateway-Execution-Logs_9upfn6zpoe/Sample2', /* required */ + filterPattern: 'GET', + interleaved: true || false, + limit: 100, + logStreamNames: [ + '4c56ff4ce4aaf9573aa5dff913df997a', + 'c45147dee729311ef5b5c3003946c48f', + '4e732ced3463d06de0ca9a15b6153677', + 'cfecdb276f634854f3ef915e2e980c31' + /* more items */ + ] +}; +cloudwatchlogs.filterLogEvents(params, function(err, data) { + if (err) console.log(err, err.stack); // an error occurred + else console.log(data); // successful response +}); \ No newline at end of file From f5516b5df4f4c579ffa85d653ba5337885c0ab54 Mon Sep 17 00:00:00 2001 From: "K.Suthagar" Date: Fri, 7 Jul 2017 18:04:37 +0530 Subject: [PATCH 2/2] update README --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a4759f1..7f820f3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -# AWS SDK for Node.js Sample Project +# AWS SDK for Node.js - CloudWatchLog Sample Project -A simple Node.js application illustrating usage of the AWS SDK for Node.js. +1. simple Node.js - Simple application to upload Hello_world file to Amzon S3 +2. cloudwatchlog.js - Application which can retrive log groups and events from AWS CloudWatchLogs +3. cloudwatchlog_filer.js - Application which can retive log based on filters from AWS CloudWatchLogs ## Requirements @@ -19,12 +21,23 @@ to connect to AWS. You can do this by creating a file named "credentials" at ~/. aws_access_key_id = aws_secret_access_key = +## Config - For CloudWatchLog Application + +You need to set up your AWS security credentials before the cloudwatchlog code is able +to connect to AWS. You can do this by creating a file named "config.json" and saving the following lines in the file: + + { + "accessKeyId": "you_access_key>, + "secretAccessKey": , + "region": + } + See the [Security Credentials](http://aws.amazon.com/security-credentials) page. It's also possible to configure your credentials via a configuration file or directly in source. See the AWS SDK for Node.js [Developer Guide](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html) for more information. -## Running the S3 sample +## Running the application sample This sample application connects to Amazon's [Simple Storage Service (S3)](http://aws.amazon.com/s3), creates a bucket, and uploads a file to that bucket. The script will automatically @@ -32,6 +45,12 @@ create the file to upload. All you need to do is run it: node sample.js +This cloudwatchlog application connects to Amazon's CloudWatchLog,and +retive the Log Groups, Log Streams, and Log Events for Filters from there. All you need to do is run it: + + node cloudwatchlogs.js + node cloudwatchlogs_filter.js + The S3 documentation has a good overview of the [restrictions for bucket names](http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html) for when you start making your own buckets.