Laptop mit Code und Notizblock
Lucas, Kiya | 28.08.2023

GitLab Review Apps with AWS CDK

Webentwicklung > GitLab Review Apps with AWS CDK

With GitLab Review Apps, an environment can be launched for every merge request. This allows to directly test changes made, without having to check out the MR separately. This results in faster reviews and moreover allows people without programming knowledge, e.g., from marketing, to provide feedback directly on the MR.

Here is how I activated review apps for our homepage.

As we deploy our homepage with the AWS CDK, the process was not too difficult:

  • I had to adjust the cdk.ts to create the stack dynamically based on environment variables:

1const ENV_NAME = process.env.HOMEPAGE_ENV_NAME;
2const ENV_TYPE = process.env.HOMEPAGE_ENV_TYPE;
4if (ENV_NAME && ENV_TYPE) {
5  new CdkStack(app, ENV_NAME, {
6    tags: {
7      Project: "Homepage",
8      responsible: "",
9      environment: ENV_TYPE,
10    },
11  });
12} else {
13  throw new Error(
14    "Missing environment variables: HOMEPAGE_ENV_NAME, HOMEPAGE_ENV_TYPE",
15  );
  • Adjust scripts in package.json:

1  "cdk": "cdk",
2  "cdk:deploy": "cdk deploy ${HOMEPAGE_ENV_NAME} --require-approval never --outputs-file ./cdk.out.json",
3  "cdk:destroy": "cdk destroy ${HOMEPAGE_ENV_NAME} --require-approval never",
  • Write a script which parses the output from the CDK to get the deployed URL:

1cat cdk.out.json
2DYNAMIC_ENVIRONMENT_URL=https://$(cat cdk.out.json | jq -r --arg env_name "$HOMEPAGE_ENV_NAME" '.[$env_name].AppRunnerServiceURL')
4echo "Deployed successfully to $DYNAMIC_ENVIRONMENT_URL 🚀"
  • Adjust gitlab-ci.yml to create the corresponding pipelines:

3  extends: .default
4  stage: deploy
5  services:
6    - docker:24.0.5-dind
7  variables:
8    DOCKER_HOST: tcp://docker:2375
9  script:
10    - npm run cdk:deploy
11    - ./scripts/  # looks in the cdk.out.json for the deployed url
12  artifacts:
13    reports:
14      dotenv: deploy.env              # lets gitlab know to look here for environment variables
15  environment:
16    url: $DYNAMIC_ENVIRONMENT_URL     # after the job, this is fetched from the deploy.env

Currently, the review app domains default to AWS App Runner domains, for example In the future, we could look into custom domains like

Of course, please consider that additional costs will incur due to the additional environments, we will need to monitor this and possibly reduce the lifespan of the environments or only deploy the environments manually.

  • What is a GitLab Review App?
  • How to set up a dynamic environment using AWS CDK?
  • How to adjust scripts in package.json to work with dynamic environment?
  • What is a script to parse the output of CDK?
  • How to adjust gitlab-ci.yml to create corresponding pipelines?
  • What are the additional costs that need to be considered?
Lucas Meurer
Lucas (Softwareentwickler)

... ist mit Leib und Seele vielseitiger Full-Stack-Entwickler am Standort Hannover. Leidenschaftlich entwickelt er nicht nur mit React und TypeScript, sondern auch WebAssembly, Rust, NestJS und NextJS... mehr anzeigen


... ist unsere engagierte und leidenschaftliche Künstliche Intelligenz und Expertin für Softwareentwicklung. Mit einem unermüdlichen Interesse für technologische Innovationen bringt sie Enthusiasmus u... mehr anzeigen

More about this topic

More from Lucas

Unsere Entwicklungsexpertise

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund