Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 9f8c0f5

Browse files
HarshCasperlukqw
andauthored
revamp app preview docs (#1397)
Co-authored-by: lukqw <39307517+lukqw@users.noreply.github.com>
1 parent 1053d92 commit 9f8c0f5

File tree

2 files changed

+63
-84
lines changed

2 files changed

+63
-84
lines changed

content/en/user-guide/cloud-sandbox/_index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ LocalStack Cloud Sandbox encompasses the following features:
1818
- Facilitate collaboration by allowing developers to test features on the same environment.
1919

2020
{{< callout >}}
21-
Cloud Sandbox is currently available on invite-only preview.
22-
If you'd like to try it out, please [contact us](https://www.localstack.cloud/demo) to request access.
21+
Cloud Sandbox is offered as a **preview** feature and under active development.
2322
{{< /callout >}}

content/en/user-guide/cloud-sandbox/application-previews/index.md

Lines changed: 62 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,116 +7,96 @@ description: Create an Application Preview to deploy your application changes in
77

88
## Introduction
99

10-
Application Preview allows you to generate an preview environment from GitHub Pull Request (PR) builds.
11-
You can use Application Preview to temporarily deploy your AWS-powered application to a LocalStack Ephemeral Instance and preview your application changes.
12-
Currently, the Application Preview are only supported for GitHub repositories using GitHub Actions.
10+
Application Preview generates a preview environment from GitHub Pull Requests (PRs).
11+
It allows temporary deployment of AWS powered applications on a LocalStack Ephemeral Instance to preview changes.
12+
This feature is currently only available for GitHub repositories that use GitHub Actions.
1313

1414
{{< callout >}}
15-
Application Preview is currently available on invite-only preview.
16-
If you'd like to try it out, please [contact us](https://www.localstack.cloud/demo) to request access.
15+
Ephemeral Instances is offered as a **preview** feature and under active development.
1716
{{< /callout >}}
1817

1918
## Getting started
2019

2120
This guide is designed for users new to Application Preview and assumes basic knowledge of GitHub Actions.
2221
We will configure a CI pipeline that runs on pull requests using GitHub Actions.
2322

24-
To get started with a ready-to-use template, you can fork the [`bref-localstack-sample`](https://github.com/localstack-samples/bref-localstack-sample) repository.
25-
The sample application deploys a serverless PHP application using Bref and the Serverless Framework.
26-
2723
### Prerequisites
2824

2925
- [LocalStack Account](https://app.localstack.cloud/)
3026
- [GitHub Account](https://github.com)
3127

3228
### Create the Application Preview
3329

34-
To create an Application Preview, you can use the [`LocalStack/setup-localstack/ephemeral/startup` action](https://github.com/localstack/setup-localstack).
30+
To create an Application Preview, use the [`LocalStack/setup-localstack` action](https://github.com/localstack/setup-localstack).
3531

36-
The sample repository has been configured to use the workflow described above.
37-
For your custom repository, create a new file named `ci-pipeline.yml` in the `.github/workflows` directory.
38-
This file will contain the CI pipeline that runs on every pull request.
39-
This pipeline deploys the application to a LocalStack Ephemeral Instance.
32+
Create a file named `preview-pipeline.yml` in the `.github/workflows` directory of your custom repository.
33+
This file should contain the CI pipeline that activates on every pull request.
4034

41-
The workflow file to create the Application Preview looks like this:
35+
The pipeline deploys the application to a LocalStack Ephemeral Instance using a `deploy.sh` script or similar for full application deployment.
36+
A comment containg the preview link is automatically added to a Pull Request when created.
4237

4338
```yaml
44-
name: Create PR Preview
45-
46-
on:
47-
pull_request:
48-
types: [opened, synchronize, reopened]
49-
50-
jobs:
51-
test:
52-
runs-on: ubuntu-latest
53-
timeout-minutes: 15
54-
steps:
55-
- name: Checkout
56-
uses: actions/checkout@v4
57-
58-
- name: Deploy Preview
59-
uses: LocalStack/setup-localstack@v0.2.2
60-
with:
61-
github-token: ${{ secrets.GITHUB_TOKEN }}
62-
localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }}
63-
preview-cmd: |
64-
# Add your custom deployment commands here.
65-
# Below is an example for the Bref Serverless application.
66-
export AWS_DEFAULT_REGION=us-east-1
67-
npm install --include=dev
68-
npm run build
69-
composer require bref/bref
70-
mv .env.example .env
71-
php artisan key:generate
72-
npm run serverless -- deploy --stage dev
73-
74-
pip install awscli-local[ver1]
75-
apiId=$(awslocal apigatewayv2 get-apis| jq -r '.Items[0].ApiId')
76-
echo "Open URL: $AWS_ENDPOINT_URL/restapis/$apiId/dev/_user_request_/"
39+
uses: LocalStack/setup-localstack@v0.2.2
40+
with:
41+
github-token: ${{ secrets.GITHUB_TOKEN }}
42+
state-backend: ephemeral
43+
state-action: start
44+
# Adding this option prevents Ephemeral Instance to be stopped after the `preview-cmd` run
45+
skip-ephemeral-stop: 'true'
46+
# Optional script/command to run
47+
preview-cmd: deploy.sh
48+
env:
49+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
7750
```
7851
79-
You will also need to configure the `LOCALSTACK_API_KEY` as a repository secret.
80-
You can find the API key on the [LocalStack Web Application](https://app.localstack.cloud/account/apikeys).
81-
The `GITHUB_TOKEN` is automatically created by GitHub and you can use it without any additional configuration.
82-
83-
### Attach the Preview URL
84-
85-
You can now attach the Preview URL to the pull request by using the [`LocalStack/setup-localstack/finish` action](https://github.com/localstack/setup-localstack).
52+
You must also set the `LOCALSTACK_API_KEY` as a repository secret, available from the [LocalStack Web Application](https://app.localstack.cloud/account/apikeys).
53+
The `GITHUB_TOKEN` is automatically generated by GitHub and requires no further configuration.
8654

87-
The sample repository has been configured to use the workflow described above.
88-
For your custom repository, create a new file named `ci-finalize.yml` in the `.github/workflows` directory.
89-
This file contains the CI pipeline that attaches a comment to the pull request with the Preview URL of the deployed application.
55+
### Stop the Application Preview
9056

91-
The workflow file to attach the Preview URL looks like this:
57+
To stop the Application Preview, you can configure the `state-action` to `stop`.
9258

9359
```yaml
94-
name: Finalize PR Preview
95-
96-
on:
97-
workflow_run:
98-
workflows: ["Create PR Preview"]
99-
types:
100-
- completed
101-
102-
jobs:
103-
test:
104-
runs-on: ubuntu-latest
105-
steps:
106-
- name: Finalize PR comment
107-
uses: LocalStack/setup-localstack/finish@v0.2.0
108-
with:
109-
github-token: ${{ secrets.GITHUB_TOKEN }}
110-
include-preview: true
60+
uses: LocalStack/setup-localstack@v0.2.2
61+
with:
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
state-backend: ephemeral
64+
state-action: stop
65+
env:
66+
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
11167
```
11268

113-
### Open a Pull Request
69+
## Configuration
70+
71+
| Input | Description | Default |
72+
|------------------------------|---------------------------------------------------------------------------|--------------|
73+
| `auto-load-pod` | Specifies which Cloud Pod to load during LocalStack startup | `None` |
74+
| `extension-auto-install` | Defines which extensions to install during LocalStack startup for Application Previews | `None` |
75+
| `lifetime` | Duration an Application Preview remains active | 30 |
76+
| `state-backend` | Starts an Application Preview, used with `state-action` to manage state | `ephemeral` |
77+
| `state-action` | Commands `start`/`stop` for managing Application Previews | |
78+
| `skip-ephemeral-stop` | Option to bypass stopping the Application Preview | `false` |
79+
| `preview-cmd` | Commands to generate an Application Preview of the PR (supports `$AWS_ENDPOINT_URL`) | |
80+
81+
## Overriding the Application Preview URL
11482

115-
Once your changes are in your repository, open a new pull request.
116-
GitHub will receive the request and trigger your workflow.
117-
You can track the workflow's status and logs in the **Checks** section of the pull request.
83+
The Application Preview URL is automatically generated and added as a comment to the Pull Request.
84+
However, if your application is served on a different URL, you can override the URL using the `LS_PREVIEW_URL`.
85+
It is beneficial if you are using a CloudFront distribution or a custom domain.
86+
87+
Here is an example of how to override the URL:
88+
89+
```yaml
90+
preview-cmd: |
91+
make build;
92+
make bootstrap;
93+
make deploy;
94+
make build-frontend;
95+
make deploy-frontend;
96+
distributionId=$(awslocal cloudfront list-distributions | jq -r '.DistributionList.Items[0].Id');
97+
echo LS_PREVIEW_URL=$AWS_ENDPOINT_URL/cloudfront/$distributionId/ >> $GITHUB_ENV;
98+
```
11899

119-
After a short delay, the workflow will update the pull request with the URL of your preview environment.
120-
Just click on it to see the changes in real-time.
100+
## Examples
121101

122-
Each time the branch is updated, the same workflow will automatically refresh the preview environment.
102+
- [Creating ephemeral application previews with LocalStack and GitHub Actions](https://docs.localstack.cloud/tutorials/ephemeral-application-previews/) and the [example repository](https://github.com/localstack-samples/sample-notes-app-dynamodb-lambda-apigateway)

0 commit comments

Comments
 (0)