What’s the preferred way to run a script after a d...
# sst
d
What’s the preferred way to run a script after a deploy? We need to register the (generated) URLs as webhooks with some external API
t
If you want to keep it all within AWS you can create a custom resource. That's effectively a lambda that runs as part of your deploy
d
seems like a very common use-case to me 😛 maybe something to include in SST?
or is it already easier than this sounds
t
It's not too crazy but probably can create a more convenient wrapper around custom resources. It's still a new pattern for me and I'm still evaluating if I like the approach
d
Thanks I’ll take a look 🙏
j
I think running scripts is a pretty common use case. There’s an open issue for adding db migration support (https://github.com/serverless-stack/serverless-stack/issues/483). But I wonder if just adding support for running any type of scripts would be more helpful. @Frank knows more about this.
f
@Danny Just curious, why not have a script in ur local, and run it after deploy? ie.
package.json
Copy code
"scripts": {
  "deploy": "sst deploy && ./my-local-script"
}
d
ah I wasn’t sure deploy is ran like that
because deploys are .. free? 😄
now I’m curious how do you differentiate those build minutes
Copy code
$ cd /tmp/seed/source/aws-stacks
$ yarn sst build --stage pr190 --region eu-central-1 --verbose
yea didn’t work 😄
f
Ah that was more like if you wanted to run something locally. When deployed through SEED, you can run the script in the
after_deploy
hook in your buildspec https://seed.run/docs/adding-a-build-spec#seedyml Alternatively, you can run it in the Post-Deploy Phase https://seed.run/docs/adding-a-post-deploy-phase.html
d
yes we have that and it’s slow
have to yarn install again
CDK managed script that only runs on deploy or remove, with access to SSM would be great 😄
f
Yup, let me talk to the team tmr, that’s something we are looking to add very soon.
Btw, are you looking to run the script on every deploy? Or only once on the first deploy?
d
in this case it only has to run when the API gateway URL is known (first deploy) or if it changes