Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awshelloworld #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -19,19 +21,36 @@ to connect to AWS. You can do this by creating a file named "credentials" at ~/.
aws_access_key_id = <your access key id>
aws_secret_access_key = <your secret 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": <your_secret_access_key>,
"region": <required_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
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.

Expand Down
55 changes: 55 additions & 0 deletions cloudwatchlogs.js
Original file line number Diff line number Diff line change
@@ -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
});
27 changes: 27 additions & 0 deletions cloudwatchlogs_filter.js
Original file line number Diff line number Diff line change
@@ -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
});