cwe_putevents.ts - AWS Code Sample


/* Copyright, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 ABOUT THIS NODE.JS EXAMPLE: This example works with AWS SDK for JavaScript version 3 (v3), which is pending release. The preview version of the SDK is available at This example is in the 'AWS SDK for JavaScript v3 Developer Guide' at Purpose: 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: ts-node cwe_putevents.ts */ // Import required AWS SDK clients and commands for Node.js const { CloudWatchEventsClient, PutEventsCommand, } = require("@aws-sdk/client-cloudwatch-events"); // Set the AWS Region const REGION = "REGION"; //e.g. "us-east-1" // Set the parameters const params = { Entries: [ { Detail: '{ "key1": "value1", "key2": "value2" }', DetailType: "appRequestSubmitted", Resources: [ "RESOURCE_ARN", //RESOURCE_ARN ], Source: "", }, ], }; // Create CloudWatch service object const cwevents = new CloudWatchEventsClient(REGION); const run = async () => { try { const data = await cwevents.send(new PutEventsCommand(params)); console.log("Success, event sent; requestID:", data.$metadata.requestId); } catch (err) { console.log("Error", err); } }; run();