Hey I wanted to split my api Stack with an NestedS...
# help
u
Hey I wanted to split my api Stack with an NestedStack where I import the api and add routes like this tuto https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.NestedStack.html and got this errors
Copy code
TypeError: Cannot read property 'slice' of undefined
    at new Function (/home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Function.ts:187:8)
    at Function.fromDefinition (/home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Function.ts:531:14)
    at Api.createFunctionIntegration (/home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Api.ts:579:23)
    at Api.addRoute (/home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Api.ts:466:26)
    at /home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Api.ts:303:12
    at Array.forEach (<anonymous>)
    at Api.addRoutes (/home/uncharted/projects/my-api/node_modules/@serverless-stack/resources/src/Api.ts:302:25)
    at new ApiGroupStack (/home/uncharted/projects/my-api/stacks/ApiGroupStack.ts:25:10)
    at new ApiStack (/home/uncharted/projects/my-api/stacks/ApiStack.ts:683:5)
    at Object.main (/home/uncharted/projects/my-api/stacks/index.ts:57:20)
wondering if someone succeded to split an api and if the error is normal ? 🤔
f
Hey @Uncharted, SST currently doesn’t support nested stacks.
Is there any specific reason why you need to use nested stacks instead of separate stacks?
u
no reason I wanted to organize better my api stacks currently I have 2 stack for my apis
f
Yeah.. internally we try to avoid using Nested Stacks. From talking to teams, it slows down the deployments a ton as you have more stacks nested.
You can actually create the Api in 1 stack, pass it to another stack, and add more routes to it. Similar to this example. Is that what you are doing right now?
u
yes that's what I m doing for now 🙂
f
ah i see.. curious why u wanted to move to nested stacks haha
u
well i reached the 500 resources limit , i searched on previous thread and it seems that even if you put common permission in defaultFunctionProps it duplicates for each route I ll try with a common role too to reduce the resources
f
Yeah, using a common role would save 2 resources per route.
You can try something like this:
Copy code
new sst.Api(this, "Api", {
  defaultFunctionProps: {
    role: new iam.Role(...)
  },
  routes: {
    ...
  }
});