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:
- Open the AWS Secrets Manager console.
- Click Store a new secret → Other type of secret.
- Add two key-value pairs:
- Key:
BROWSERSTACK_USERNAME, Value: your BrowserStack username. - Key:
BROWSERSTACK_ACCESS_KEY, Value: your BrowserStack access key.
- Key:
- On the next screen, set the secret name to
browserstack/loadtest. - Save.
To create the CodeBuild project:
- Open the AWS CodeBuild console → Create build project.
- Source: connect your source repository.
- Environment: Managed image → Ubuntu standard 7.0 (on-demand).
-
Service role: create a new role; ensure the role has
secretsmanager:GetSecretValuepermission for the secret ARN created above. -
Buildspec: choose Use a buildspec file with the default filename
buildspec.yml. - 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 forparameter-store:with the corresponding parameter names. - For projects that don’t use Secrets Manager, you can also set
BROWSERSTACK_USERNAMEandBROWSERSTACK_ACCESS_KEYdirectly 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:GetSecretValuepermission for the secret ARN. Without this, the build fails at theinstallphase 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
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!