Anyone happen to know if there are cdk constructs ...
# help
g
Anyone happen to know if there are cdk constructs to create an algolia index? If not anyone have any guidance for how I might create one to do this for me if it is possible to do?
t
Not that I'm aware of unfortunately. I know there's a terraform provider but probably not worth pulling that in just for one service
If you want to really go for it, you can use the
sst.Script
construct to create / delete the algolia index using the Algolia API
g
Yeah the scripts do not run for local dev though correct? Was hoping to get one that would work locally too.
t
The scripts do run for
sst start
g
Oh ok great that should work then 🙂
a
Did you check the construct library?
g
Thats an interesting site didnt know it existed, but seems there isnt one listed. Creating a small script to create/delete wont be hard though.
a
😞
r
Re: ss.Scripts running when using sst start. I got an error when I tried that earlier saying something like I needed to specify
enableLiveDev: false
for the function
t
I gotta try it. Just realizing how powerful it can be to turn other parts of my system into IaC
a
@thdxr which parts?
t
I guess I've been sticking mostly to AWS services but I'm starting to use Planetscale more so can use that to spin up / seed databases
g
Yeah I normally do as well but aws doesnt have any serverless search which is a bit annoying (and wild). Figured I might as well setup a script to handle creating/deleting indexes for me since I want to create a deploy per branch and that would be a lot of manual creation for each branch to work.
f
Hey @Garret Harp, I think the
Script
construct is a perfect fit for your use case. I’m making some changes to the
Script
construct to make it more “powerful”. If you decide to use it, let me know how it’d look like. And I can make sure the
Script
construct has everything u need.
@Ross Coundon @thdxr if you’re passing in an
sst.Function
to
Script
, you’d have to make sure
enableLiveDev
is disabled. If you were to define the function inline, that’s automatically done for u.
r
Right - so the upshot is you can't run a Script if you're running locally?
t
You can, it just can't be running in live debug mode because the stack gets blocked waiting for your local execution which won't happen
r
Ah, I see, I hadn't caught the distinction between running locally and running locally in a debug session in the discussion
f
lol this sounds confusing 😂
Script
is a custom resource, so the function you provide it will run during CloudFormation deploy. And when you run
sst start
, the local environment (the websocket connect) starts up AFTER CloudFormation finishes deploying.
So if
enableLiveDev
is ON,
Script
will try to connect to ur local to run the code, but the local environment has started yet, and
Script
will fail, in turn the while CFN deploy will fail.
We can definitely fix this by starting up local environment BEFORE CloudFormation starts to deploy.
r
Thanks Frank, that makes more sense now in my little brain 😄
g
Ok so I have the script working for creating my indexes whenever the stack is created/update but how would I go about removal? Is this possible?
f
Hey @Garret Harp, I’m literally working on this right now. I’m planning to change the format to:
Copy code
new sst.Script(this, "MyScript", {
  onCreate: "src/script.create",
  onUpdate: "src/script.update",
  onDelete: "src/script.delete",
});
Does this make sense?
g
Yeah that would be perfect 🙂
f
Should be ready in a couple of hours. I will keep you posted.
Hey @Garret Harp, just released this 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
g
Great, thanks 😄