Skip to main content
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

AWS CodeBuild CI/CD with BrowserStack Load Testing

Integrate BrowserStack Load Testing into AWS CodeBuild projects to run load tests as part of your AWS-native CI/CD workflows.

You can add BrowserStack Load Testing to your AWS CodeBuild projects so that every build triggers a load test.

Prerequisites

Make sure you have the following before you start:

  • A BrowserStack account with access to Load Testing.
  • An AWS account with permissions to create CodeBuild projects and AWS Secrets Manager secrets.
  • A source repository (CodeCommit, GitHub, GitHub Enterprise, Bitbucket, or Amazon S3) for CodeBuild to pull from.
  • BrowserStack credentials stored in AWS Secrets Manager. You can find the credentials on your account’s profile page:
    • BROWSERSTACK_USERNAME: Your BrowserStack username.
    • BROWSERSTACK_ACCESS_KEY: Your BrowserStack access key.

To store the credentials in AWS Secrets Manager:

  1. Open the AWS Secrets Manager console.
  2. Click Store a new secretOther type of secret.
  3. Add two key-value pairs:
    • Key: BROWSERSTACK_USERNAME, Value: your BrowserStack username.
    • Key: BROWSERSTACK_ACCESS_KEY, Value: your BrowserStack access key.
  4. On the next screen, set the secret name to browserstack/loadtest.
  5. Save.

To create the CodeBuild project:

  1. Open the AWS CodeBuild console → Create build project.
  2. Source: connect your source repository.
  3. Environment: Managed image → Ubuntu standard 7.0 (on-demand).
  4. Service role: create a new role; ensure the role has secretsmanager:GetSecretValue permission for the secret ARN created above.
  5. Buildspec: choose Use a buildspec file with the default filename buildspec.yml.
  6. Save and trigger a build.

AWS CodeBuild buildspec

Use the following AWS CodeBuild buildspec to download the BrowserStack CLI, run a sample Playwright-based load test, and upload JUnit XML reports as a build artifact. Save it at the repository root as buildspec.yml.

version: 0.2

env:
  variables:
    BROWSERSTACK_RUN: "true"
  secrets-manager:
    BROWSERSTACK_USERNAME: browserstack/loadtest:BROWSERSTACK_USERNAME
    BROWSERSTACK_ACCESS_KEY: browserstack/loadtest:BROWSERSTACK_ACCESS_KEY

phases:
  install:
    runtime-versions:
      nodejs: 20
    commands:
      - apt-get update -qq && apt-get install -y -qq curl unzip ca-certificates
  pre_build:
    commands:
      - echo "Running unit tests"
  build:
    commands:
      - |
        OS=$(uname -s); ARCH=$(uname -m)
        [ "$OS" = "Darwin" ] && OS=macos || OS=linux
        case "$ARCH" in *arm*) ARCH=arm64 ;; *) ARCH=x64 ;; esac
        curl -fL "https://load-api.browserstack.com/api/v1/binary?os=${OS}&arch=${ARCH}" -o browserstack-cli.zip
        unzip -oq browserstack-cli.zip
        chmod +x browserstack-cli
      - |
        curl -L https://github.com/browserstack/browserstack-playwright-load-testing-sample/archive/refs/heads/CI/CD-Sample-Playwright.tar.gz \
          | tar -xz --strip-components=1
      - ./browserstack-cli load run

artifacts:
  files:
    - reports-*/browserstack-load-test-report-*.xml
  name: load-test-report-$CODEBUILD_BUILD_NUMBER
  discard-paths: no

Result

When this build runs, it:

  • Downloads the BrowserStack CLI for the current runner OS and architecture.
  • Fetches the BrowserStack Playwright load-testing sample project.
  • Starts a BrowserStack Load Testing run using BrowserStack credentials pulled from AWS Secrets Manager.
  • Uploads the generated JUnit XML reports as a build artifact named load-test-report-<build-number>.

Notes

  • The buildspec uses AWS Secrets Manager for credentials. If you prefer AWS Systems Manager Parameter Store, swap the secrets-manager: block for parameter-store: with the corresponding parameter names.
  • For projects that don’t use Secrets Manager, you can also set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY directly in the CodeBuild project’s environment variables (least secure; credentials are visible to anyone with project read access).
  • Ensure the CodeBuild service role has secretsmanager:GetSecretValue permission for the secret ARN. Without this, the build fails at the install phase with a “secret not authorized” error.
  • The default Ubuntu 7.0 image runs on Linux x64. If you need ARM or Windows, switch the Environment image at project setup time.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle