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.aws.amazon.com/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 AWS 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 AWS 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
--name
and--schedule-expression
parameters.Examples:
The following sample command uses --schedule-expression to create a rule called
MyRule2
that filters EventBridge on a schedule.aws events put-rule --schedule-expression 'cron(15 10 ? * 6L 2002-2005)' --name MyRule2
-
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
.{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
-
Use the following command to create the
Role-for-MyRule
role 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
.{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codepipeline:StartPipelineExecution" ], "Resource": [ "arn:aws:codepipeline:us-west-2:80398EXAMPLE:MyFirstPipeline" ] } ] }
-
Use the following command to attach the new
CodePipeline-Permissions-Policy-for-EB
permissions policy to theRole-for-MyRule
role you created.aws iam put-role-policy --role-name Role-for-MyRule --policy-name CodePipeline-Permissions-Policy-For-EB --policy-document file://permissionspolicyforCWE.json
-