Test triggers for an AWS CodeCommit repository - AWS CodeCommit

Test triggers for an AWS CodeCommit repository

You can test the triggers that have been created for a CodeCommit repository. Testing involves running the trigger with sample data from your repository, including the most recent commit ID. If no commit history exists for the repository, sample values consisting of zeroes are generated instead. Testing triggers helps you confirm you have correctly configured access between CodeCommit and the target of the trigger, whether that is an AWS Lambda function or an Amazon Simple Notification Service notification.

Test a trigger for a repository (console)

  1. Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home.

  2. In Repositories, choose the repository where you want to test a trigger for repository events.

  3. In the navigation pane for the repository, choose Settings, and then choose Triggers.

  4. Choose the trigger you want to test, and then choose Test trigger. You should see a success or failure message. If successful, you should also see a corresponding action response from the Lambda function or the Amazon SNS topic.

Test a trigger for a repository (AWS CLI)

  1. At a terminal (Linux, macOS, or Unix) or command prompt (Windows), run the get-repository-triggers command to create a JSON file with the structure of all of the triggers configured for your repository. For example, to create a JSON file named TestTrigger.json with the structure of all of the triggers configured for a repository named MyDemoRepo:

    aws codecommit get-repository-triggers --repository-name MyDemoRepo >TestTrigger.json

    This command creates a file named TestTriggers.json in the directory where you ran the command.

  2. Edit the JSON file in a plain-text editor and make the changes to the trigger statement. Replace the configurationId pair with a repositoryName pair. Save the file.

    For example, if you want to test a trigger named MyFirstTrigger in the repository named MyDemoRepo so that it applies to all branches, replace the configurationId with repositoryName and then save a file that looks similar to the following as TestTrigger.json:

    { "repositoryName": "MyDemoRepo", "triggers": [ { "destinationArn": "arn:aws:sns:us-east-2:111122223333:MyCodeCommitTopic", "branches": [ "main", "preprod" ], "name": "MyFirstTrigger", "customData": "", "events": [ "all" ] } ] }
  3. At the terminal or command line, run the test-repository-triggers command. This updates all triggers for the repository, including the changes you made to the MyFirstTrigger trigger:

    aws codecommit test-repository-triggers --cli-input-json file://TestTrigger.json

    This command returns a response similar to the following:

    { "successfulExecutions": [ "MyFirstTrigger" ], "failedExecutions": [] }