# AWS DevOps

> Trigger Testsigma test plans from AWS CodeBuild directly or as a stage in an AWS CodePipeline.

AWS DevOps triggers Testsigma test plans two ways: a CodeBuild project running the trigger script, or a CodePipeline running that build project between its source and deploy stages.

## Prerequisites

- An API key and the test plan ID.
- The [shell script](https://testsigma.com/docs/v2/integrations/ci-cd/shell-script/) (`cicd-api.sh`) in your repository.

## Trigger from a CodeBuild project

1. **Create a build project**: under the **Build** section, click **Build projects** and create a new build project.

2. **Fill in the project configuration**: select the **Source Provider** and **Repository** (the example uses GitHub). Set the **Buildspec name** to your `.yml` file name.

3. **Commit the buildspec**: update the `.yml` file in the repository. The sample here is `aws_codebuild.yml`:

    ```yaml title="aws_codebuild.yml"
    version: 0.2
    phases:
      install:
        runtime-versions:
          java: corretto11
      pre_build:
        commands:
          - echo Nothing to do in the pre_build phase...
      build:
        commands:
          - bash cicd-api.sh
      post_build:
        commands:
          - echo Build completed on `date`
    ```

4. **Set the script inputs**: `cicd-api.sh`, called in the `build` phase, carries the test plan details. Update its inputs and add it to the repository:

    ```shell title="cicd-api.sh inputs"
    #********START USER_INPUTS ********

    TESTSIGMA_API_KEY=  API Keys tab in Testsigma>

    TESTSIGMA_TEST_PLAN_ID= 
    MAX_WAIT_TIME_FOR_SCRIPT_TO_EXIT=180
    REPORT_FILE_PATH=./junit-report.xml
    RUNTIME_DATA_INPUT="buildurl=http://test.testsigma.com,data1=testdata"

    #********END USER_INPUTS***********
    ```

5. **Start the build**: in CodeBuild, click **Start build**. Track progress in the build logs. The execution ID for the test plan appears in the **REST API call to start Test Plan** section.

## Trigger from a CodePipeline

CodePipeline runs the source, build, and deploy stages together. Reuse the CodeBuild project you created above as the build stage; the tests then gate the deploy.

1. **Create a pipeline**: in the CodePipeline service, click **Create pipeline**.

2. **Fill in the build details**: select the repository, then pick the CodeBuild project created earlier as the build stage.

3. **Review and create**: complete the pipeline settings, source, and deploy stage details, then click **Create Pipeline**. The run triggers as soon as the pipeline is created.
