Use an event to start a CodePipeline execution - CodeArtifact

Use an event to start a CodePipeline execution

This example demonstrates how to configure an Amazon EventBridge rule so that an AWS CodePipeline execution starts when a package version in a CodeArtifact repository is published, modified, or deleted.

Configure EventBridge permissions

You must add permissions for EventBridge to use CodePipeline to invoke the rule that you create. To add these permissions using the AWS Command Line Interface (AWS CLI), follow step 1 in Create a CloudWatch Events Rule for a CodeCommit Source (CLI) in the AWS CodePipeline User Guide.

Create the EventBridge rule

To create the rule, use the put-rule command with the --name and --event-pattern parameters. The event pattern specifies values that are matched against the contents of each event. The target is triggered if the pattern matches the event. For example, the following pattern matches CodeArtifact events from the myrepo repository in the my_domain domain.

aws events put-rule --name MyCodeArtifactRepoRule --event-pattern \ '{"source":["aws.codeartifact"],"detail-type":["CodeArtifact Package Version State Change"], "detail":{"domainName":["my_domain"],"domainOwner":["111122223333"],"repositoryName":["myrepo"]}}'

Create the EventBridge rule target

The following command adds a target to the rule so that when an event matches the rule, a CodePipeline execution is triggered. For the RoleArn parameter, specify the Amazon Resource Name (ARN) of the role created earlier in this topic.

aws events put-targets --rule MyCodeArtifactRepoRule --targets \ 'Id=1,Arn=arn:aws:codepipeline:us-west-2:111122223333:pipeline-name, RoleArn=arn:aws:iam::123456789012:role/MyRole'