https://serverless-stack.com/ logo
#help
Title
# help
d

Dan Van Brunt

11/04/2021, 4:51 PM
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

thdxr

11/04/2021, 4:58 PM
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

Dan Van Brunt

11/04/2021, 5:00 PM
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

thdxr

11/04/2021, 5:02 PM
Maybe I'm wrong will let Frank answer
f

Frank

11/04/2021, 5:59 PM
@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

Dan Van Brunt

11/04/2021, 6:01 PM
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

Frank

11/04/2021, 6:02 PM
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

Dan Van Brunt

11/04/2021, 6:03 PM
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

Frank

11/04/2021, 6:04 PM
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

Dan Van Brunt

11/04/2021, 6:05 PM
Can I just take a step back and ask… why are you rebuilding in order to
sst remove
?
f

Frank

11/04/2021, 6:05 PM
we are rebuilding CDK, so we know what are the stacks we need to remove
we are not rebuilding the Lambda code
d

Dan Van Brunt

11/04/2021, 6:05 PM
Can’t you just call
cdk destroy
f

Frank

11/04/2021, 6:06 PM
yeah, that does a
cdk build
internally
d

Dan Van Brunt

11/04/2021, 6:06 PM
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

Frank

11/04/2021, 6:07 PM
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

Dan Van Brunt

11/04/2021, 6:08 PM
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

Frank

11/04/2021, 6:24 PM
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

Dan Van Brunt

11/04/2021, 8:16 PM
no rush at all… but thanks!
f

Frank

11/09/2021, 7:00 AM
Implemented. Will cut a release tmr!
Hey @Dan Van Brunt, it’s out in v0.50.3
d

Dan Van Brunt

11/09/2021, 8:18 PM
Woot! Thanks 🙏