> :loudspeaker: Update In v0.41.0, we added the...
# general
f
📢 Update
In v0.41.0, we added the
sst.Script
construct. You can use this script to do things like seeding the database, etc. A couple of things to note: • The script is not run on ur local machine or on the build server, it’s run inside a Lambda function; • The script uses your the Lambda function’s IAM credentials, not your local credentials; • The script can run for a maximum of 15 minutes; • The script is run on every deployment; • Live Lambda Dev is not enabled for scripts;
Copy code
new Script(this, "Script", {
  function: "src/script.main",
  params: {
    hello: "world",
    tableName: table.tableName,
  },
});
Here are some more examples.
g
This is awesome, been looking to do exactly this over the last couple of days. I was looking at using a custom resources in cloudformation. Is that what is being used for this behind the scenes?
f
@George Evans Yup! You bet!
What were you planning to use this for? Just curious.
g
Awesome! For running post deploy database migrations mainly 👍
f
Ah gotcha! Keep me posted on ur experience!
b
oh wow
this is hugely useful
so much for my custom cfn resource that my stack depends on to get similar functionality
I’ve been thinking a lot about collecting deployment telemetry from my services, this would make it very portable A+ to sst maintainers 😄
f
Thanks @Blake E! Could you share an example of what you are doing inside the scirpt? Just curious 😁
b
when I finish
still trying to decide on mechanism (and what meta is readily available in this construct)
but basically beforeStack > lambda > eventbridge: “deploy started” afterStack > lambda > eventbridge: “deploy finished” and then I’ll reduce eventbridge into some state (that’s my current thinking)
f
Ah gotcha!
g
@Frank this is fantastic. I noticed that the deployment process outputs to the console when the Lambda/Script fails, but is silent when it succeeds. I was wondering if it would make sense to output any responses that the Lambda/Script returns? For example for a database initializer script, I’m returning the list of databases, which could be used to confirm that in fact the new database was created.
Copy code
return {
          'statusCode': 200,
          'headers': {'Content-Type': 'application/json'},
          'body': json.dumps({**databases})
       }