I've got an "after_remove" script I'm trying to ru...
# seed
p
I've got an "after_remove" script I'm trying to run that deletes a load of tables out of our AWS Aurora PostgreSQL DB cluster using the aws rds-data CLI. The command works fine when I run it locally but when I run it via SEED the tables aren't deleted and no errors are reported. Is there anyway to determine what happened? Some logs somewhere?
f
Hey @Phil Astle, can you DM me a link to the build?
p
Morning @Frank! The build doesn't exist as it was removed without any errors
That's the bit I was wondering how to work around so I can debug after_remove commands not doing what I wanted 🙂
I suspect my issue is that the IAM user used by SEED needs to be given RDS access (or higher access) - something I'm going to try shortly. However, it was more about how to debug issues in the after_remove if there's nothing left in the UI to click on to look at logs, etc.
f
Oh I see. Yeah that’s a good point.
p
I make them occasionally ;)
f
We should keep the deleted apps around for ppl to do cleanup investigation.
I will add that to our roadmap.
p
I reckon that would do it - sounds good to me!
Thanks for taking the time to reply - hopefully you've not done any big all nighters for a while!
f
As a temporary workaround, you can make the
after_remove
script always fail, so the stage doesn’t get successfully removed. And you can go in and look at the logs.
p
Why didn't I think of that...!? I had it fail a bunch of times whilst I was trying to get the command syntax right and noticed that behavior... I should have thought of that myself - I'm going to blame it being a Monday!
Hmm... Now that I can remove the stack again (thanks for the fix!) I'm still not getting an error from the removal of the stage on my SST services - even though I've put a deliberate mistake into the script (which I've seen be reported on the Serverless services). Could SST services maybe not be running the after_remove functions (though they run the before_build one)..? I'll do some more digging
Doesn't appear to be running before_remove scripts either - there's nothing in the log
f
Hey Phil, yeah
before_remove
and
after_remove
are currently not supported for SST apps.
p
That would explain why I couldn't get them to do anything!
Thankfully we've got a mixture of SST and Serverless apps so I can just put the before_remove/after_remove onto one of them for now. The idea was that in one of our SST services we create a bunch of tables in an Aurora PostgreSQL DB via the new Script construct you added recently. The idea was to use the after_remove to delete the tables from the DB, so we don't leave loads of extra ones around.
I wanted the cleanup to be in the same service as the service that creates the items that needed cleaning up - my OCD shining through.
f
I see. Would it work if you could use the Script construct to do the cleanup as well?
I think it makes sense if you do both setup and teardown of the tables in the same manner. What do you think?
p
Sure, my first thought was to use a script.
f
Just curious, are you configuring the Script construct to run only once? Or are you running it on every deploy?
p
On every deploy atm, with checks in to see if the tables already exist. I store a version number in a table so that in the future I can run upgrade scripts on the DB schema, should I need to.
f
Got it. If you like the Script solution, I can push out an update to the Script construct so that you know the lifecycle is REMOVE, and you can run the cleanup scripts.
Does that work for you?
p
That sounds like it should work. So I assume you'll change the script from just running on deploy to running on other events too? Then we can check what context it's running in (by looking at the lifecycle)?
Would it only run on remove and deploy or other lifecycles too?
f
What other lifecycles do you have in mind?
p
I don't know what other lifecycles are available tbh. If deploy and remove are a couple of them, maybe other lifecycles might be useful for someone at some point?
Maybe for running migration scripts, etc?
I really am very much an AWS newcomer
f
Yeah, deploy and remove are the two main lifecycles. Let me talk to the team, and I will get back to you shortly!
p
I've should have a workaround for now by using a serverless' service before_remove script, and then I'm off work the rest of the week. If/once you plug something in I'll definitely switch over to the script solution - much neater!
f
Hey @Phil Astle, a side note as I was pulling up your builds, it seems your “app-admin” service is failing. It seems the static site wasn’t npm installed. You’d probably want to run
npm install
in the static site folder in the
before_build
step for this service.
p
Thanks @Frank - I'll pass that on to the person who's fiddling with that one atm 🙂
Hi @Frank, any updates/thoughts on changing Script to work with remove as well? We just moved all of the rest of our Serverless stuff to SST so I've nowhere left to hook in my tidy up code now!
f
Yup.. working on it! Will have some update real soon 😁
p
Thanks a lot! Been using SEED and SST a lot recently and you guys being so responsive is making it easier and a lot less scary!
f
Thanks @Phil Astle! That’s really motivating to hear 💪
Hey @Phil Astle, added the ability to run Script on remove in v0.46.0.
There’s a minor breaking change to the input format for
Script
, you can follow this doc to update - https://docs.serverless-stack.com/constructs/Script#upgrading-to-v0460
p
Thanks Frank! I'll look at this on Monday 🙂
Plugged in and seems to work a treat! 👍
f
AWESOME