Skip to content

Latest commit

 

History

History
 
 

cloudwatch-logs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Amazon Cloudwatch Logs JavaScript SDK v3 code examples

Purpose

The code examples in this directory demonstrate how to work with Amazon CloudWatch Logs using the AWS SDK for JavaScript (v3).

You can use Amazon CloudWatch Logs to monitor, store, and access your log files from Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS CloudTrail, Route 53, and other sources.

Code examples

API examples

Note: All code examples are written in ECMAscript 6 (ES6). For guidelines on converting to CommonJS, see JavaScript ES6/CommonJS syntax.

Important

  • As an AWS best practice, grant this code least privilege, or only the permissions required to perform a task. For more information, see Grant least privilege in the AWS Identity and Access Management User Guide.
  • This code has not been tested in all AWS Regions. Some AWS services are available only in specific AWS Regions. For more information, see the AWS Regional Services List on the AWS website.
  • Running this code might result in charges to your AWS account.

Running the code

Prerequisites

  1. Clone the AWS Code Samples repo to your local environment. See the Github documentation for instructions.

  2. Install the dependencies listed in the package.json.

Note: These dependencies include the client modules for the AWS services that this example requires, which include @aws-sdk/client-cloudwatch-logs.

npm install node -g 
cd javascriptv3/example_code/cloudwatch-logs
npm install
  1. In your text editor, update user variables specified in the Inputs section of the sample file.

  2. Run sample code:

cd src
node [example name].js 

Unit tests

Unit tests<./tests>_ are provided for most examples, using the Jest <https://jestjs.io/>_ framework.

For example, to run tests on the cloudwatch-logs folder, enter the following sequence of commands at the command prompt:

npm install node -g
cd javascriptv3/example_code/cloudwatch-logs/tests
npm install
npm test

Resources