Skip to content
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ __pycache__
venv
composer.*
vendor/
main.zip
main.zip
node_modules
35 changes: 35 additions & 0 deletions javascript/example_code_v3/cloudwatch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Typescript environment for Amazon Cloudwatch examples
Environment for AWS SDK for JavaScript (V3) AWS Cloudwatch samples. For more information, see the
[AWS documentation for these examples](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples.html).

Amazon CloudWatch enables you to collect, access, and correlate this data on a single platform from across all your AWS resources, applications, and services.

This is a workspace where you can find working AWS SDK for JavaScript (V3) Cloudwatch samples.

**NOTE:** The AWS SDK for JavaScript (V3) is written in TypeScript so, for consistency, these examples are also in TypeScript. TypeScript is
a super-set of JavaScript so these examples can also be run as JavaScript.
# Getting Started

1. Clone the [AWSDocs Code Samples repo](https://github.com/awsdocs/aws-doc-sdk-examples) to your local environment.
See [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) for
instructions.

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

**Note**: These include the client modules for the AWS services required in these example,
which are the *@aws-sdk/client-cloudwatch*, *@aws-sdk/client-cloudwatch-events*, and *@aws-sdk/client-cloudwatch-logs*.
```
npm install ts-node -g // If you prefer to use JavaScript, enter 'npm install node -g' instead
cd javascript/example_code_v3/cloudwatch
yarn
```
3. If you prefer to use JavaScript, change the sample file extension from ```.ts``` to ```.js```.

4. In your text editor, update user variables specified in the 'Inputs' section of the sample file.

5. Run sample code:
```
cd src
ts-node [sample name].ts // If you prefer to use JavaScript, enter 'node [sample name].js' instead
```

20 changes: 20 additions & 0 deletions javascript/example_code_v3/cloudwatch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "aws-sdk-v3-cloudwatch-examples",
"version": "1.0.0",
"main": "index.js",
"repository": "git@github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascript/example_code_v3/cloudwatch.git",
"author": "Brian Murray <brmur@amazon.com>, Alex Forsyth <alex-git@amazon.com>",
"license": "MIT",
"dependencies": {
"@aws-sdk/client-cloudwatch": "^1.0.0-gamma.6",
"@aws-sdk/client-cloudwatch-events": "^1.0.0-gamma.6",
"@aws-sdk/client-cloudwatch-logs": "^1.0.0-gamma.6",
"@aws-sdk/node-http-handler": "^1.0.0-gamma.5",
"@aws-sdk/types": "^0.1.0-gamma.6",
"ts-node": "^9.0.0"
},
"devDependencies": {
"@types/node": "^14.0.23",
"typescript": "^4.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-creating-alarms.html.

Purpose:
cw_deletealarm.js demonstrates how to delete Amazon CloudWatch alarms.
cw_deletealarm.ts demonstrates how to delete Amazon CloudWatch alarms.

Inputs (replace in code):
- REGION
- ALARM_NAMES (e.g., Web_Server_CPU_Utilization)

Running the code:
node cw_deletealarm.js
ts-node cw_deletealarm.ts
*/
// snippet-start:[cw.JavaScript.alarms.deleteAlarmsV3]

Expand Down Expand Up @@ -44,4 +44,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.alarms.deleteAlarmsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-creating-alarms.html.

Purpose:
cw_describealarms.js demonstrates how to retrieve information about Amazon CloudWatch alarms.
cw_describealarms.ts demonstrates how to retrieve information about Amazon CloudWatch alarms.

Inputs (replace in code):
- REGION

Running the code:
node cw_describealarms.js
ts-node cw_describealarms.ts
*/
// snippet-start:[cw.JavaScript.alarms.describeAlarmsV3]

Expand Down Expand Up @@ -46,4 +46,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.alarms.describeAlarmsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-using-alarm-actions.html.

Purpose:
cw_disablealarmactions.js demonstrates how to disable actions for an Amazon CloudWatch alarm.
cw_disablealarmactions.ts demonstrates how to disable actions for an Amazon CloudWatch alarm.

Inputs (replace in code):
- REGION
- ALARM_NAME

Running the code:
node cw_disablealarmactions.js
ts-node cw_disablealarmactions.ts
*/
// snippet-start:[cw.JavaScript.alarms.disableAlarmActionsV3]

Expand Down Expand Up @@ -44,4 +44,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.alarms.disableAlarmActionsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-using-alarm-actions.html.

Purpose:
cw_enablealarmactions.js demonstrates how to enable actions for Amazon CloudWatch alarms.
cw_enablealarmactions.ts demonstrates how to enable actions for Amazon CloudWatch alarms.

Inputs (replace in code):
- REGION
- ALARM_NAME
- ACTION_ARN

Running the code:
node cw_enablealarmactions.js
ts-node cw_enablealarmactions.ts
*/
// snippet-start:[cw.JavaScript.alarms.enableAlarmActionsV3]

Expand Down Expand Up @@ -76,4 +76,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.alarms.enableAlarmActionsV3]
exports.run = run;
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide//cloudwatch-examples-getting-metrics.html.

Purpose:
cw_listmetrics.js demonstrates how to list metrics for Amazon CloudWatch.
cw_listmetrics.ts demonstrates how to list metrics for Amazon CloudWatch.

Inputs (replace in code):
- REGION

Running the code:
node cw_listmetrics
ts-node cw_listmetrics.ts
*/
// snippet-start:[cw.JavaScript.metrics.listMetricsV3]

Expand Down Expand Up @@ -51,4 +51,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.metrics.listMetricsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-creating-alarms.html.

Purpose:
cw_putmetricalarm.js demonstrates how to create or update an Amazon CloudWatch alarm and associate it with particular metrics.
cw_putmetricalarm.ts demonstrates how to create or update an Amazon CloudWatch alarm and associate it with particular metrics.

Inputs (replace in code):
- REGION

Running the code:
node cw_putmetricalarm.js
ts-node cw_putmetricalarm.ts
*/
// snippet-start:[cw.JavaScript.alarms.putMetricAlarmV3]

Expand Down Expand Up @@ -64,4 +64,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.alarms.putMetricAlarmV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inputs (replace in code):
- REGION

Running the code:
node cw_putmetricdata.js
ts-node cw_putmetricdata.ts
*/
// snippet-start:[cw.JavaScript.metrics.putMetricDataV3]

Expand Down Expand Up @@ -58,4 +58,5 @@ const run = async () => {
};
run();
// snippet-end:[cw.JavaScript.metrics.putMetricDataV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-sending-events.html.

Purpose:
cwe_putevents.js demonstrates how to send custom events to Amazon CloudWatch Events so they can be matched with rules.
cwe_putevents.ts demonstrates how to send custom events to Amazon CloudWatch Events so they can be matched with rules.

Inputs (replace in code):
- REGION
- RESOURCE_ARN

Running the code:
node cwe_putevents.js
ts-node cwe_putevents.ts
*/
// snippet-start:[cwEvents.JavaScript.cwe.putEventsV3]

Expand Down Expand Up @@ -55,4 +55,5 @@ const run = async () => {
};
run();
// snippet-end:[cwEvents.JavaScript.cwe.putEventsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-sending-events.html.

Purpose:
cwe_putrule.js demonstrates how to create or update an Amazon CloudWatch Events rule.
cwe_putrule.ts demonstrates how to create or update an Amazon CloudWatch Events rule.

Inputs (replace in code):
- REGION IAM_ROLE_ARN

Running the code:
node cw_deletealarm.js
ts-node cw_deletealarm.ts
*/
// snippet-start:[cwEvents.JavaScript.cwe.putRuleV3]

Expand Down Expand Up @@ -48,4 +48,5 @@ const run = async () => {
};
run();
// snippet-end:[cwEvents.JavaScript.cwe.putRuleV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-sending-events.html.

Purpose:
cwe_puttargets.js demonstrates how to add or update a target to an Amazon CloudWatch Events rule.
cwe_puttargets.ts demonstrates how to add or update a target to an Amazon CloudWatch Events rule.

Inputs (replace in code):
- REGION
- LAMBDA_FUNCTION_ARN

Running the code:
node cwe_puttargets.js
ts-node cwe_puttargets.ts
*/
// snippet-start:[cwEvents.JavaScript.cwe.putTargetsV3]

Expand Down Expand Up @@ -52,4 +52,5 @@ const run = async () => {
};
run();
// snippet-end:[cwEvents.JavaScript.cwe.putTargetsV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-subscriptions.html.

Purpose:
cwl_deletesubscriptionfilter.js demonstrates how to delete an Amazon CloudWatch Logs filter.
cwl_deletesubscriptionfilter.ts demonstrates how to delete an Amazon CloudWatch Logs filter.

Inputs :
- REGION
- FILTER
- LOG_GROUP

Running the code:
node cwl_deletesubscriptionfilter.js
ts-node cwl_deletesubscriptionfilter.ts
*/
// snippet-start:[cwLogs.JavaScript.cwl.deleteSubscriptionFilterV3]

Expand Down Expand Up @@ -51,4 +51,5 @@ const run = async () => {
};
run();
// snippet-end:[cwLogs.JavaScript.cwl.deleteSubscriptionFilterV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-subscriptions.html

Purpose:
cwl_describesubscriptionfilters.js demonstrates how to list the subscription filters for an Amazon CloudWatch Logs group.
cwl_describesubscriptionfilters.ts demonstrates how to list the subscription filters for an Amazon CloudWatch Logs group.

Inputs (replace in code): (all into command line below)
- REGION
- GROUP_NAME

Running the code:
node cwl_describesubscriptionfilters.js
ts-node cwl_describesubscriptionfilters.ts
*/
// snippet-start:[cwLogs.JavaScript.cwl.describeSubscriptionFiltersV3V3]

Expand Down Expand Up @@ -47,4 +47,5 @@ const run = async () => {
};
run();
// snippet-end:[cwLogs.JavaScript.cwl.describeSubscriptionFiltersV3V3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ scheduled for release later in 2020, and the topic containing this example will
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/cloudwatch-examples-subscriptions.html.

Purpose:
cwl_putsubscriptionfilter.js demonstrates how to create or update a subscription filter for an Amazon CloudWatch Logs group.
cwl_putsubscriptionfilter.ts demonstrates how to create or update a subscription filter for an Amazon CloudWatch Logs group.

Inputs (replace in code): (all into command line below)
- REGION
Expand All @@ -17,7 +17,7 @@ Inputs (replace in code): (all into command line below)
- LOG_GROUP

Running the code:
node cwl_putsubscriptionfilter.js
ts-node cwl_putsubscriptionfilter.ts
*/
// snippet-start:[cwLogs.JavaScript.cwl.putSubscriptionFilterV3]

Expand Down Expand Up @@ -50,4 +50,5 @@ const run = async () => {
}
};
// snippet-end:[cwLogs.JavaScript.cwl.putSubscriptionFilterV3]
exports.run = run; //for unit tests only
//for unit tests only
// module.exports = {run};
Loading