Got this when tearing down (`npx sst remove`) just...
# help
d
Got this when tearing down (
npx sst remove
) just now…
Copy code
Error: No child with id: 'Code'
    at Node.findChild (/Users/me/Projects/projx/node_modules/constructs/src/construct.ts:95:13)
    at ConstructNode.findChild (/Users/me/Projects/projx/node_modules/@aws-cdk/core/lib/construct-compat.ts:215:70)
    at /Users/me/Projects/projx/lib/constructs/ContentfulApp/ContentfulApp.ts:100:50
    at Array.forEach (<anonymous>)
    at new ContentfulApp (/Users/me/Projects/projx/lib/constructs/ContentfulApp/ContentfulApp.ts:97:20)
    at new MyStack (/Users/me/Projects/projx/lib/constructs/MyStack/MyStack.ts:58:5)
    at Object.main (/Users/me/Projects/projx/lib/index.ts:13:3)
    at Object.<anonymous> (/Users/me/Projects/projx/.build/run.js:93:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
I believe this is regarding this block of code …
Copy code
apiSite.routes.forEach((route, index) => {
      const handlerFunction = apiSite.getFunction(route)
      if (!handlerFunction) throw new Error(`Can't find function`)
      const functionAsset = handlerFunction.node.findChild('Code') as s3Assets.Asset

      const updaterCR = this.createLambdaCodeReplacer(`Route${index}`, functionAsset)
      handlerFunction.node.addDependency(updaterCR)
    })
works going up but apparently not going down?
t
hm
I don't know CFN well enough to have an idea of why this is happening
maybe @Frank has a clue
My understanding was
sst remove
is just
sst build
to generate the cfn template and then telling CFN to remove what's in the template
Does
sst build
work?
d
oh? I thought it told the stack to delete?
perhaps thats the issue than…. maybe there is staticsite build steps that are not taken during
sst remove
?
t
Maybe I'm wrong will let Frank answer
f
@Dan Van Brunt
apiSite
is an
sst.Api
construct right?
On
sst remove
, to speed it up, we don’t bundle the function, we use dummy inline code
d
ah. hmmm so is there a way to handling it in a way that replicates what the nodes look like so the findChild(‘Code’) works? or a diff way of me writting that?
f
I think there’s an eazy fix here, instead of this
Copy code
code: new lambda.InlineCode("placeholder"),
We do:
Copy code
code: lambda.Code.fromAsset("path/to/placeholder");
We just create a dummy placeholder Lambda Code instance.
that should work for u i think, right @Dan Van Brunt ?
d
right…. but what if the user inlined their code?
I mean it works for my case…. just trying to think if it works for someone who inlines
f
when u run
sst build
, code is always created using
lambda.Code.fromAsset
, never inlined.
This change just makes the
sst remove
and
sst build
consistent
d
Can I just take a step back and ask… why are you rebuilding in order to
sst remove
?
f
we are rebuilding CDK, so we know what are the stacks we need to remove
we are not rebuilding the Lambda code
d
Can’t you just call
cdk destroy
f
yeah, that does a
cdk build
internally
d
I mean… why is
sst remove
re-synth-ing
why not just call
cdk destroy
and be done with it
cdk destroy
doesn’t re synth/build does it?
f
cdk destroy
does a
synth
and then calls CFN to remove stack one by one
sst remove
does a
synth
and then trys to remove non-dependent stacks all together
they do similar things, just a bit quicker
cdk destroy
has to
synth
first, otherwise, it doesn’t know all the stacks in the CDK app.
d
ok…. didn’t know that…. then I guess thats my question…. do we know why
cdk destroy
doesn’t just
aws cloudformation delete-stack
?
ah
could be dynamic num of stacks
ok… I’m cool with that change if it works for everyone
f
I can get this in by tonite. @Dan Van Brunt feel free to take a crack at it if u guys are in a rush.
d
no rush at all… but thanks!
f
Implemented. Will cut a release tmr!
Hey @Dan Van Brunt, it’s out in v0.50.3
d
Woot! Thanks 🙏