@@ -39,11 +39,21 @@ const createLogGroup = async (logGroupName) => {
3939 * @param {string } ruleName - The name of the rule.
4040 */
4141const deleteRule = async ( ruleName ) => {
42- const cweClient = new CloudWatchEventsClient ( { } ) ;
43- const command = new DeleteRuleCommand ( {
44- Name : ruleName ,
45- } ) ;
46- await cweClient . send ( command ) ;
42+ try {
43+ const cweClient = new CloudWatchEventsClient ( { } ) ;
44+ const command = new DeleteRuleCommand ( {
45+ Name : ruleName ,
46+ } ) ;
47+ await cweClient . send ( command ) ;
48+ } catch ( caught ) {
49+ if ( caught instanceof Error ) {
50+ console . error (
51+ `Failed to delete rule: ${ ruleName } . ${ caught . name } : ${ caught . message } ` ,
52+ ) ;
53+ } else {
54+ throw caught ;
55+ }
56+ }
4757} ;
4858
4959/**
@@ -52,28 +62,48 @@ const deleteRule = async (ruleName) => {
5262 * @param {string[] } targetIds - The IDs of the targets to remove.
5363 */
5464const removeTargets = async ( ruleName , targetIds ) => {
55- const cweClient = new CloudWatchEventsClient ( { } ) ;
56- const command = new RemoveTargetsCommand ( {
57- Rule : ruleName ,
58- Ids : targetIds ,
59- } ) ;
60- await cweClient . send ( command ) ;
65+ try {
66+ const cweClient = new CloudWatchEventsClient ( { } ) ;
67+ const command = new RemoveTargetsCommand ( {
68+ Rule : ruleName ,
69+ Ids : targetIds ,
70+ } ) ;
71+ await cweClient . send ( command ) ;
72+ } catch ( caught ) {
73+ if ( caught instanceof Error ) {
74+ console . error (
75+ `Failed to remove targets: ${ targetIds } from rule: ${ ruleName } . ${ caught . name } : ${ caught . message } ` ,
76+ ) ;
77+ } else {
78+ throw caught ;
79+ }
80+ }
6181} ;
6282
6383/**
6484 * Delete a log group.
6585 * @param {string } logGroupName - The name of the log group.
6686 */
6787const deleteLogGroup = async ( logGroupName ) => {
68- const cwlClient = new CloudWatchLogsClient ( { } ) ;
69- const command = new DeleteLogGroupCommand ( {
70- logGroupName : logGroupName ,
71- } ) ;
72- await cwlClient . send ( command ) ;
88+ try {
89+ const cwlClient = new CloudWatchLogsClient ( { } ) ;
90+ const command = new DeleteLogGroupCommand ( {
91+ logGroupName : logGroupName ,
92+ } ) ;
93+ await cwlClient . send ( command ) ;
94+ } catch ( caught ) {
95+ if ( caught instanceof Error ) {
96+ console . error (
97+ `Failed to delete log group: ${ logGroupName } . ${ caught . name } : ${ caught . message } ` ,
98+ ) ;
99+ } else {
100+ throw caught ;
101+ }
102+ }
73103} ;
74104
75105describe ( "CloudWatch Events integration test" , ( ) => {
76- const logGroupName = "test-log-group" ;
106+ const logGroupName = "cloudwatch-events- test-log-group" ;
77107 const ruleName = "test-rule" ;
78108 const rulePattern = JSON . stringify ( {
79109 source : [ "my.app" ] ,
0 commit comments