File tree Expand file tree Collapse file tree 4 files changed +34
-19
lines changed
example-construct-library Expand file tree Collapse file tree 4 files changed +34
-19
lines changed Original file line number Diff line number Diff line change @@ -133,21 +133,15 @@ export abstract class AgentBase extends Resource implements IAgent {
133133 * @returns An EventBridge Rule configured for agent events
134134 */
135135 public onEvent ( id : string , options : events . OnEventOptions = { } ) : events . Rule {
136- // Create rule with minimal props and event pattern
137- const rule = new events . Rule ( this , id , {
138- description : options . description ,
139- eventPattern : {
140- source : [ 'aws.bedrock' ] ,
141- detail : {
142- 'agent-id' : [ this . agentId ] ,
143- } ,
136+ const rule = new events . Rule ( this , id , options ) ;
137+ rule . addEventPattern ( {
138+ source : [ 'aws.bedrock' ] ,
139+ detail : {
140+ 'agent-id' : [ this . agentId ] ,
144141 } ,
145142 } ) ;
146143
147- // Add target if provided
148- if ( options . target ) {
149- rule . addTarget ( options . target ) ;
150- }
144+ rule . addTarget ( options . target ) ;
151145 return rule ;
152146 }
153147
Original file line number Diff line number Diff line change @@ -293,16 +293,27 @@ describe('Agent', () => {
293293
294294 const rule = agent . onEvent ( 'TestRule' , {
295295 description : 'Custom rule description' ,
296+ ruleName : 'MyCustomEventRuleName' ,
297+ eventPattern : {
298+ account : [ '123456789012' ] ,
299+ region : [ 'us-east-1' ] ,
300+ detail : {
301+ test : 'value' ,
302+ } ,
303+ } ,
296304 } ) ;
297305
298306 expect ( rule ) . toBeDefined ( ) ;
299307 Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Events::Rule' , {
300308 Description : 'Custom rule description' ,
309+ Name : 'MyCustomEventRuleName' ,
301310 EventPattern : {
302311 source : [ 'aws.bedrock' ] ,
303312 detail : {
304313 'agent-id' : [ { 'Fn::GetAtt' : [ Match . stringLikeRegexp ( 'TestAgent[A-Z0-9]+' ) , 'AgentId' ] } ] ,
305314 } ,
315+ account : [ '123456789012' ] ,
316+ region : [ 'us-east-1' ] ,
306317 } ,
307318 } ) ;
308319 } ) ;
Original file line number Diff line number Diff line change @@ -201,11 +201,7 @@ abstract class ExampleResourceBase extends Resource implements IExampleResource
201201 * as it simplifies the implementation code (less branching).
202202 */
203203 public onEvent ( id : string , options : events . OnEventOptions = { } ) : events . Rule {
204- const rule = new events . Rule ( this , id , {
205- description : options . description ,
206- ruleName : options . ruleName ,
207- crossStackScope : options . crossStackScope ,
208- } ) ;
204+ const rule = new events . Rule ( this , id , options ) ;
209205 rule . addTarget ( options . target ) ;
210206 rule . addEventPattern ( {
211207 // obviously, you would put your resource-specific values here
Original file line number Diff line number Diff line change @@ -121,13 +121,27 @@ describe('Example Resource', () => {
121121 } ) ;
122122
123123 test ( 'onEvent adds an Event Rule' , ( ) => {
124- exampleResource . onEvent ( 'MyEvent' ) ;
124+ exampleResource . onEvent ( 'MyEvent' , {
125+ description : 'Custom rule description' ,
126+ ruleName : 'MyCustomEventRuleName' ,
127+ eventPattern : {
128+ account : [ '123456789012' ] ,
129+ region : [ 'us-east-1' ] ,
130+ detail : {
131+ test : 'value' ,
132+ } ,
133+ } ,
134+ } ) ;
125135
126136 Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Events::Rule' , {
137+ Description : 'Custom rule description' ,
138+ Name : 'MyCustomEventRuleName' ,
127139 EventPattern : {
128140 detail : {
129- 'example-resource-name ' : [ EXAMPLE_RESOURCE_NAME ] ,
141+ 'test ' : 'value' ,
130142 } ,
143+ account : [ '123456789012' ] ,
144+ region : [ 'us-east-1' ] ,
131145 } ,
132146 } ) ;
133147 } ) ;
You can’t perform that action at this time.
0 commit comments