2023-10-13 12:09:10 -04:00
# CloudWatch code examples for the SDK for JavaScript (v3)
2023-01-10 10:31:32 -05:00
## Overview
2023-10-13 12:09:10 -04:00
Shows how to use the AWS SDK for JavaScript (v3) to work with Amazon CloudWatch.
<!--custom.overview.start-->
<!--custom.overview.end-->
2020-10-02 16:34:29 +01:00
2023-10-13 12:09:10 -04:00
_ CloudWatch provides a reliable, scalable, and flexible monitoring solution that you can start using within minutes. _
2020-09-30 15:40:42 +01:00
2023-10-13 12:09:10 -04:00
## ⚠ Important
2023-01-10 10:31:32 -05:00
2024-01-09 12:33:12 -05:00
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing ](https://aws.amazon.com/pricing/ ) and [Free Tier ](https://aws.amazon.com/free/ ).
2024-01-04 12:50:33 -05:00
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
2023-01-10 10:31:32 -05:00
2023-10-13 12:09:10 -04:00
<!--custom.important.start-->
<!--custom.important.end-->
2021-10-22 20:28:30 +01:00
## Code examples
2020-09-30 15:40:42 +01:00
2023-10-13 12:09:10 -04:00
### Prerequisites
2020-09-30 15:40:42 +01:00
2023-10-13 12:09:10 -04:00
For prerequisites, see the [README ](../../README.md#Prerequisites ) in the `javascriptv3` folder.
2022-12-02 12:57:03 -06:00
2024-01-04 12:50:33 -05:00
2023-10-13 12:09:10 -04:00
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
2023-01-05 14:52:50 -05:00
2023-10-13 12:09:10 -04:00
### Single actions
2023-01-06 08:23:00 -05:00
2023-10-13 12:09:10 -04:00
Code excerpts that show you how to call individual service functions.
2020-09-30 15:40:42 +01:00
2024-04-30 12:22:08 -07:00
- [DeleteAlarms ](actions/delete-alarms.js#L4 )
- [DescribeAlarmsForMetric ](actions/describe-alarms.js#L4 )
- [DisableAlarmActions ](actions/disable-alarm-actions.js#L4 )
- [EnableAlarmActions ](actions/enable-alarm-actions.js#L4 )
- [ListMetrics ](actions/list-metrics.js#L4 )
- [PutMetricAlarm ](actions/put-metric-alarm.js#L4 )
- [PutMetricData ](actions/put-metric-data.js#L4 )
2023-10-13 12:09:10 -04:00
2024-01-04 12:50:33 -05:00
<!--custom.examples.start-->
<!--custom.examples.end-->
2023-10-13 12:09:10 -04:00
## Run the examples
2020-09-30 15:40:42 +01:00
2023-01-10 10:31:32 -05:00
### Instructions
2020-09-30 15:40:42 +01:00
2023-10-13 12:09:10 -04:00
**Note ** : All code examples are written in ECMAscript 6 (ES6). For guidelines on converting to CommonJS, see
[JavaScript ES6/CommonJS syntax ](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sdk-examples-javascript-syntax.html ).
2023-01-10 10:31:32 -05:00
**Run a single action **
2023-10-02 12:43:28 -04:00
2023-10-13 12:09:10 -04:00
``` bash
node ./actions/<fileName>
```
**Run a scenario **
2024-08-28 14:08:16 -04:00
2023-10-13 12:09:10 -04:00
Most scenarios can be run with the following command:
``` bash
node ./scenarios/<fileName>
```
2021-10-22 20:28:30 +01:00
2024-08-28 14:08:16 -04:00
**Run with options **
Some actions and scenarios can be run with options from the command line:
``` bash
node ./scenarios/<fileName> --option1 --option2
```
[util.parseArgs ](https://nodejs.org/api/util.html#utilparseargsconfig ) is used to configure
these options. For the specific options available to each script, see the `parseArgs` usage
for that file.
2023-10-13 12:09:10 -04:00
<!--custom.instructions.start-->
<!--custom.instructions.end-->
2021-10-22 20:28:30 +01:00
2024-01-04 12:50:33 -05:00
2023-10-13 12:09:10 -04:00
### Tests
2021-10-22 20:28:30 +01:00
2023-10-13 12:09:10 -04:00
⚠ Running tests might result in charges to your AWS account.
2024-01-04 12:50:33 -05:00
2023-10-13 12:09:10 -04:00
To find instructions for running these tests, see the [README ](../../README.md#Tests )
in the `javascriptv3` folder.
2024-01-04 12:50:33 -05:00
2023-10-13 12:09:10 -04:00
<!--custom.tests.start-->
<!--custom.tests.end-->
2021-10-22 20:28:30 +01:00
2023-01-10 10:31:32 -05:00
## Additional resources
2021-10-22 20:28:30 +01:00
2023-10-13 12:09:10 -04:00
- [CloudWatch User Guide ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html )
- [CloudWatch API Reference ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/Welcome.html )
- [SDK for JavaScript (v3) CloudWatch reference ](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/cloudwatch )
<!--custom.resources.start-->
<!--custom.resources.end-->
---
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2020-09-30 15:40:42 +01:00
2024-01-04 12:50:33 -05:00
SPDX-License-Identifier: Apache-2.0