Start a pipeline on a schedule
You can set up a rule in EventBridge to start a pipeline on a schedule.
Create an EventBridge rule that schedules your pipeline to start (console)
To create an EventBridge rule with a schedule as the event source
Open the Amazon EventBridge console at https://console.amazonaws.cn/events/
. -
In the navigation pane, choose Rules.
-
Choose Create rule, and then under Rule detail, choose Schedule.
-
Set up the schedule using a fixed rate or expression. For information, see Schedule Expression for Rules
. -
In Targets, choose CodePipeline.
-
Enter the pipeline ARN for the pipeline execution for this schedule.
Note
You can find the pipeline ARN under Settings in the console. See View the pipeline ARN and service role ARN (console).
-
Choose one of the following to create or specify an IAM service role that gives EventBridge permissions to invoke the target associated with your EventBridge rule (in this case, the target is CodePipeline).
-
Choose Create a new role for this specific resource to create a service role that grants EventBridge permissions to start your pipeline executions.
-
Choose Use existing role to enter a service role that grants EventBridge permissions to start your pipeline executions.
-
-
Choose Configure details.
-
On the Configure rule details page, enter a name and description for the rule, and then choose State to enable the rule.
-
If you're satisfied with the rule, choose Create rule.
Create an EventBridge rule that schedules your pipeline to start (CLI)
To use the Amazon CLI to create a rule, call the put-rule command, specifying:
-
A name that uniquely identifies the rule you are creating. This name must be unique across all of the pipelines you create with CodePipeline associated with your Amazon account.
-
The schedule expression for the rule.
To create an EventBridge rule with a schedule as the event source
-
Call the put-rule command and include the
--nameand--schedule-expressionparameters.Examples:
The following sample command uses --schedule-expression to create a rule called
MyRule2that filters EventBridge on a schedule.aws events put-rule --schedule-expression 'cron(15 10 ? * 6L 2002-2005)' --name MyRule2 -
To add CodePipeline as a target, call the put-targets command and include the following parameters:
-
The
--ruleparameter is used with therule_nameyou created by using put-rule. -
The
--targetsparameter is used with the listIdof the target in the list of targets and theARNof the target pipeline.
The following sample command specifies that for the rule called
MyCodeCommitRepoRule, the targetIdis composed of the number one, indicating that in a list of targets for the rule, this is target 1. The sample command also specifies an exampleARNfor the pipeline. The pipeline starts when something changes in the repository.aws events put-targets --rule MyCodeCommitRepoRule --targets Id=1,Arn=arn:aws:codepipeline:us-west-2:80398EXAMPLE:TestPipeline -
-
Grant permissions for EventBridge to use CodePipeline to invoke the rule. For more information, see Using resource-based policies for Amazon EventBridge.
-
Use the following sample to create the trust policy to allow EventBridge to assume the service role. Name it
trustpolicyforEB.json. -
Use the following command to create the
Role-for-MyRulerole and attach the trust policy.aws iam create-role --role-name Role-for-MyRule --assume-role-policy-document file://trustpolicyforEB.json -
Create the permissions policy JSON as shown in this sample for the pipeline named
MyFirstPipeline. Name the permissions policypermissionspolicyforEB.json. -
Use the following command to attach the new
CodePipeline-Permissions-Policy-for-EBpermissions policy to theRole-for-MyRulerole you created.aws iam put-role-policy --role-name Role-for-MyRule --policy-name CodePipeline-Permissions-Policy-For-EB --policy-document file://permissionspolicyforCWE.json
-