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

Jason S

05/26/2022, 6:16 AM
Hi team, is it best practice to create separate API stacks for different APIs? For example, I have a
notes
REST API with associated verbs. I also have a
transactions
API with associated verbs. Should I create two separate modules/stacks - one for each API?
a

Ashishkumar Pandey

05/26/2022, 7:24 AM
You can have multiple API Gateways in the same stack as well. Think of a stack as a group of infrastructure which has resources closely related to each other. You could build your entire application in a single API Gateway or you could use 10. My primary reason of using multiple gateways it to be able to avoid triggering per gateway limits and to be able to finely tune the authentication and authorisation levels per API / route.
j

Jason S

05/26/2022, 7:36 AM
so something like this:
Copy code
export default class ApiStack extends Stack {
  constructor(scope, id, props) {
    super(scope, id, props):
    api1 = new Api(this,"Api1", {...});
    api2 = new Api(this,"Api2", {...});
    api3 = new Api(this,"Api3", {...});
  }
}
a

Ashishkumar Pandey

05/26/2022, 7:37 AM
yep, that’ll work.
j

Jason S

05/26/2022, 7:37 AM
This will create one AGW with the routes defined in each of the
new API
?
a

Ashishkumar Pandey

05/26/2022, 7:38 AM
no, each API is another API Gateway instance.
j

Jason S

05/26/2022, 7:39 AM
So to keep 1 instance I would define all my routes in the same
new Api
?
a

Ashishkumar Pandey

05/26/2022, 7:39 AM
yes, exactly.
j

Jason S

05/26/2022, 7:40 AM
Got it thanks Ashishkumar
a

Ashishkumar Pandey

05/26/2022, 7:40 AM
of course.