has anyone figured out how to set up an environmen...
# general
has anyone figured out how to set up an environment where the front end has preview branches deployed? my old setup was obviously built for a single developer (or two), but it was: most resources had one dev instance (bucket-dev, database-dev, etc) and a prod instance. when I’d open a PR, it deploys to pr-xxx.(domain), and that would use
which pointed to the dev instances of resources, dev API endpoint, etc. now that I’m using SST w/ multiple devs in their own AWS accounts, I’m not really sure how to set this up. if a PR is opened and a preview branch is deployed, how will it know where to point for the non-production resources it depends on?
I tend to build a full environment for each PR so there's no shared resources. But if there are I do this through ssm params pointing at resources
yeah, that’s what I mean.. there shouldn’t be shared resources. so for example, when a developer opens a PR and pr-110.myapp is created.. how does it know how to set its
env var to point to the right place?
I do this sharing resources from the other stacks.
exports the url, and
receives it by parameter.
Actually is not exporting, it’s just exposing it with a public attribute.
Due API and Web both are stacks referenced on my
🤔 I still don’t know how that would work. how would my CI/CD setup deploying the preview branch know what value to use for the API URL?
On each PR, I deploy a new Web-UI instance.
You mean for the UI repository?
yeah, the front end app. right now it just uses
with hardcoded API URL, GraphQL URL, etc. but with this multi-dev SST setup, that won’t work .. can’t hardcode those.
if I have 10 developers on the team, then there are potentially 10 different API URLs
But your FE app lives in a different repo?
So I had the same problem… what I did is.. 1. Before deploying the Stacks, pull FE code from their repo 2. Deploy all the APIs and export their URLs 3. Build the UI, receiving the exported URLs by paramter 4. Deploy the UI
That means I have 1 UI for each PR.
That’s why I’m saying that my SST is also deploying the FE, is the same for you?
I’m following a mono-repo architecture, but having the FE in a different repo, and merging all together on the ci/cd.
no, my FE is totally separate repo.. it’s a Vue app. so I don’t think those steps would work for me. like, step #3.. the UI being built in CI/CD has no way to receive the API URLs
No, then you can’t follow the PR schema.
For me it’s also another repo, that doesn’t matter.
You can pull from the other repo, and SST will deploy it.
ah I see, you’re deploying it using SST
I’m using AWS’s CI/CD
If you want to have only 1 FE instance, you can create a Config screen, and they can put the API URL manually.
Well, SST deploys everything for me.
UI, APIs, everything.
You can still do it in your usecase.
not sure how, I’ll have to brainstorm on it later
Did you check the monorepo repository?
which one?
Which has example of react app + sst.
The one that Frank built, let me check.
You are going to do this…
Copy code
const service1 = new Service1Stack(app, "service1-stack");
  const service2 = new Service2Stack(app, "service2-stack");
  new WebsiteStack(app, "website-stack", {
    api1: service1.api,
    api2: service2.api,
I can’t move my front end into the SST repo though
I dunno if that will work. Vue has its own specific setup.
You can clone the repo or use sub-module from git.
so then SST deploys the front end.. are you using GitHub Actions for your SST CI/CD?
I’m using seed, but should be similar.
SST deploys React apps really easy, but is nothing more than just a helper.
You can do the same steps for vue… creating s3, creating sub-domain, etc etc.
If you use React, they already built a helper construct.
Or maybe ask Frank if they plan to build a construct for Vue.
The other solution is what I’ve said… you can create a Config page in your front-end, where the QA or developer can put the API_URL manually, but that requires some team-agreements.
Or maybe could be a query parameter, and the CI/CD generates it somehow.
Those are some of the ideas, due I’ve been thinking the same as you are, couple of weeks ago.
that’s true, maybe in staging mode, the front end can ask for the API URL to be input.. rather than rely on the env var
I’ll have to look at all my options and see what’s doable, and not too time-consuming to set up
thanks for the ideas 🙂
Hey guys, just wanted to chime in with what ppl are doing on Seed, but should be applicable to any CI.
So the out of the box way would be moving the Vue app into SST, and the
construct can automatically replace the deployed API URL in ur Vue app.
If u can’t move it into SST, you can export the API URL as
, and in the CI for ur frontend, as long as u know which PR it is, you can import value via AWS CLI.
the first scenario could work.. I’m not too hot on the idea of merging front end & back end into the same repo. I can see situations where I’d want to hire strictly front-end or back-end devs, and having the separation is ideal. I dunno if the 2nd scenario would work, since I’m not using Route 53 to assign specific URLs to the dev API endpoint. it’s just the API Gateway default (xxxxxxxxxxxxx.execute-api.us-east-1.amazonaws.com)
AWS Amplify Console (their CI/CD solution) apparently has a way to pull env vars from SSM parameters. so.. I might be able to leverage that to put the API/GraphQL URLs into SSM so the build process can grab them. it’d work as long as two devs didn’t open PRs at the same time, since the build config file can only read from one SSM param
tricky stuff 🤔
Yeah this is a classic problem. My recommendation is to merge into the same repo if you're team is submitting prs across frontend and backend. If you get to a place where backend moves independently of frontend you can split things up and have the front usually use a stable release of the backend. You can create a contingency to repoint to a different env through SSM if needed
I've seen people do this with PR tags as well but that's more work
No need to merge repos, you can use git submodules or clones during build time.
The final effect is the same.