is `this.addOutputs({...})` sync or async? I'm wo...
# help
a
is
this.addOutputs({...})
sync or async? I'm wondering If I can run some code after it that can start an external service that can grab the env variables from sst
t
All the code you write inside the stack doesn't actually do anything. It creates a plan that is later applied so if you need to grab variables it needs to happen after the deployment is done
a
how do I do that
t
you'd have to query AWS's api an get the stack outputs
a
hmm, it would be nice to add a helper function inside the stack that does that automagically
t
It can't happen from inside the stack constructor
one second
a
something like
this.afterStackUpdate()
etc.
t
@Frank when you have a chance can you provide some suggestions here? I think we should just support this more directly in
sst-env
but I'm not familiar with the inner workings of it
a
an idea could be to pass a boolean to some option to set the env variables in the build process
i'm assuming the env variables are not set during the buildCommand process and only done after the build.
regarding env variables, can a web app be 2 levels nested from the root for sst-env to work? can it be a sub-sub directory?
getting this error
sst-env: Cannot find any SST environment outputs in /Users/myUser/ProjectA
which is 2 levels above my ui project
f
Yeah,
sst-env
currently only works for
StaticSite
constructs
@Abdul Taleb That explains what it’s not working for RN project.
I agree we should definitely provide a helper here. And as @thdxr suggested, we could expand the use-case for
sst-env
.
@Abdul Taleb can I see what you are trying to output (ie. this.addOutputs())? And what are the build environment variable names you are planning to set?
a
mainly userPool info, stage and API urls. I haven't started but I have my API and my static site setup. Now I'm wondering how I can include my RN project if I want to do some local dev
f
For now, you can use the
--outputs-file
flag to generate a JSON file with all the stack outputs. ie.
sst start --outputs-file outputs.json
Then you can write a script to parse the
outputs.json
and set the build environment variable for your react native start command.
Does that work for you?
a
I'm using
sst-env
with a StaticSite construct and I'm getting the above error
b
I actually did exactly what Frank was mentioning by parsing the json outputs for my own scripting after.
(I was building an analog to
sls logs -f functionName
so my dev team would be able to easily tail deployed cloudwatch logs w/o
sst start
)
a
Thanks all for your help. I'll definitely take these ideas for my RN app. Also, it seems like two similar topics/questions of mine got mixed with one, apologies for the confusion. I'm facing an issue with my static website mentioned in this comment https://serverless-stack.slack.com/archives/C01JG3B20RY/p1631160478392400?thread_ts=1631156658.370300&cid=C01JG3B20RY any idea what's going on or how to fix?
^I'm using the
StaticSite
construct as mentioned in the docs, but getting that error when I run
npm run start
t
^ Did you run sst start first?
a
yes
Folder structure is like this:
Copy code
Project
- sst.json
- lib/
- ui/
  - StaticSiteA/
  - StaticSiteB/
- services/
  ...
- packages/
  ...
t
hm I've setup a similar structure. Can you check
Project/.build
for something like
.build/static-site-environment-output-values.json
a
yup they are there
t
I have this exact setup without issue 😦
let me see what this code is doing
a
thanks!
t
maybe recreated the issue
ok can you paste your build/static-site-environment-output-values.json here
a
Copy code
[{"id":"project-a","path":"ui/project-a/src","stack":"dev-new-project","environmentOutputs":{"API_URL":"<https://xxxxxxxx.execute-api.us-east-1.amazonaws.com>","ENVIRONMENT":"dev","GOOGLE_MAP_API":"xxxxxxxxxxxxxxxxxxxxx","__DEV__":"true","CASE_FILES_BUCKET":"dev-new-project-filesbucketxxxxxx-xxxxxxxxx","AWS_REGION":"us-east-1","USER_POOL":"us-east-1_xxxxxxxxx","IDENTITY_POOL_ID":"us-east-1:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","USER_POOL_CLIENT_ID":"xxxxxxxxxxxxxxxxxxxxxxx"}}]
t
Ah so here's the issue
you can see how in the path it says
"path":"ui/project-a/src"
a
missing a "/" ?
t
sst-env is currently expecting the path you're running it from to match the staticsite path because typically that points to where package.json is located
Yours is under
src/
is there a way you can point to just
ui/project-a
?
a
yes
package.json is in
ui/project-a
let me try that
t
gonna push a change to make this error more clear
a
great, I'd be happy to review, was just looking at the script.js file
t
We can also consider making it a match if any child directories match