Hey super heroes! I want to write some of the sta...
# sst
r
Hey super heroes! I want to write some of the stack outputs to a local JSON file (Similar to how the
StaticSite.environment
field writes to the
static-site-environment-output-values.json
) How would I do that? My specific use case is that I'm setting up DynamoDB Onetable, and I want to put the table name and function ARN into a config file for it so I don't need to manually grab them and paste.
r
Assuming you're in a JS/TS environment, you could just use fs.writeFile() and grab the various outputs you need. We pass an object to this.addOutputs(). You could JSON.stringify that same object and write it to disk
r
The problem is that the stack hasn't deployed at that time, so it just outputs tokens.
I'm not sure. I'm sure someone knows 🙂
g
sst deploy
takes an
--outputs-file
parameter
r
Thanks @Gabriel Bleu! I missed that! Do you know if there is a way to "hard code" that?
g
Like adding it to the start script in
package.json
?
r
I guess I could... but then how to run a script afterwards to take the required info from the file and write the file I need? The
sst start
command doesn't terminate.
SST hooks would be cool to run local stuff after deployments.
r
Oh yeah, of course
j
Just letting @Frank @thdxr know about the hooks idea.
f
Hey @Ryan
I want to put the table name and function ARN into a config file
Do you want to do this on
sst deploy
or
sst start
?
r
Hi @Frank, on sst start, or deploy. Either in this case.
m
cdk has the option save outputs to a file in json format using the --outputs-file flag
cdk deploy --outputs-file outputs.json
sst supports this flag https://docs.serverless-stack.com/packages/cli#options
r
I could make it work with that, if I ran that and then other commands by npm scripts. But it would probably save a few errors and frustrations in the future if there was a way to do it directly.