Create an EventBridge rule for a CodeCommit source (CloudFormation template)
To use CloudFormation to create a rule, update your template as shown here.
To update your pipeline CloudFormation template and create EventBridge rule
-
In the template, under
Resources, use theAWS::IAM::RoleCloudFormation 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? Adding the
AWS::IAM::Roleresource enables CloudFormation to create permissions for EventBridge. This resource is added to your CloudFormation stack. -
-
In the template, under
Resources, use theAWS::Events::RuleCloudFormation resource to add an EventBridge rule. This event pattern creates an event that monitors push changes to your repository. When EventBridge detects a repository state change, the rule invokesStartPipelineExecutionon your target pipeline.Why am I making this change? Adding the
AWS::Events::Ruleresource enables CloudFormation to create the event. This resource is added to your CloudFormation stack. -
(Optional) To configure an input transformer with source overrides for a specific image ID, use the following YAML snippet. The following example configures an override where:
-
The
actionName,Sourcein this example, is the dynamic value, defined at pipeline creation, not derived from the source event. -
The
revisionType,COMMIT_IDin this example, is the dynamic value, defined at pipeline creation, not derived from the source event. -
The
revisionValue, <revisionValue> in this example, is derived from the source event variable. -
The output variables for
BranchNameandValueare specified.
Rule: my-rule Targets: - Id: MyTargetId Arn: pipeline-ARN InputTransformer: sourceRevisions: actionName:SourcerevisionType:COMMIT_IDrevisionValue: <revisionValue> variables: - name:BranchNamevalue:value -
-
Save the updated template to your local computer, and then open the CloudFormation console.
-
Choose your stack, and then choose Create Change Set for Current Stack.
-
Upload the template, and then view the changes listed in CloudFormation. These are the changes to be made to the stack. You should see your new resources in the list.
-
Choose Execute.
To edit your pipeline's PollForSourceChanges parameter
Important
In many cases, the PollForSourceChanges parameter defaults to true when
you create a pipeline. When you add event-based change detection, you must add the
parameter to your output and set it to false to disable polling. Otherwise, your
pipeline starts twice for a single source change. For details, see Valid settings for the
PollForSourceChanges parameter.
-
In the template, change
PollForSourceChangestofalse. If you did not includePollForSourceChangesin your pipeline definition, add it and set it tofalse.Why am I making this change? Changing this parameter to
falseturns off periodic checks so you can use event-based change detection only.