Create an EventBridge rule for an Amazon ECR source (Amazon CloudFormation template)
To use Amazon CloudFormation to create a rule, use the template snippet as shown here.
To update your pipeline Amazon CloudFormation template and create EventBridge rule
-
In the template, under
Resources
, use theAWS::IAM::Role
Amazon CloudFormation resource to configure the IAM role that allows your event to start your pipeline. This entry creates a role that uses two policies:-
The first policy allows the role to be assumed.
-
The second policy provides permissions to start the pipeline.
Why am I making this change? You must create a role that can be assumed by EventBridge to start an execution in our pipeline.
-
-
In the template, under
Resources
, use theAWS::Events::Rule
Amazon CloudFormation resource to add an EventBridge rule for the Amazon ECR source. This event pattern creates an event that monitors commits to your repository. When EventBridge detects a repository state change, the rule invokesStartPipelineExecution
on your target pipeline.Why am I making this change? You must create an event with a rule that specifies how an image push must be made, and a target that names the pipeline to be started by the event.
This snippet uses an image named
eb-test
with a tag oflatest
.Note
To view the full event pattern supported for Amazon ECR events, see Amazon ECR Events and EventBridge or Amazon Elastic Container Registry Events.
-
Save the updated template to your local computer, and then open the Amazon CloudFormation console.
-
Choose your stack, and then choose Create Change Set for Current Stack.
-
Upload the template, and then view the changes listed in Amazon CloudFormation. These are the changes to be made to the stack. You should see your new resources in the list.
-
Choose Execute.