Is it unnecessary to use the Function construct to...
# sst
c
Is it unnecessary to use the Function construct to create lambdas for functions that are included as routes in SST’s Api construct? It looks like the Api construct may be creating a new lambda for each route automatically (e.g. functionnameEndpoint….)
m
I do it when I want to use a single function for multiple routes that are explicitly defined
f
@Clayton u r 🎯,
sst.Api
creates an
sst.Function
for each route. If you want to use the same Function for multiple routes, you can create a Function manually like @Michael Clifford suggested.
r
Just a heads-up, there seems to be an issue with reusing a function multiple times but with different env vars when running
sst start
as they appear to overwrite one another's env vars unpredictably. Raised it here
c
Thanks guys, that helps a lot. @Frank I think it’d helpful to note the implicit creation of Functions for routes on the Api Construct docs. I didn’t connect the dots and was trying to explicitly create functions for route handlers via the Function construct, resulting in confusion why properties like env vars were missing. @Michael Clifford or Frank - Would you mind sharing a code snippet that shows how you are assigning an explicitly created Function to multiple API routes to reference the correct, unique handler within function for each route? @Ross Coundon that’s good to know about that issue - thanks for the heads up. Also curious, do any of you have advice on creating a single function/file that has multiple handlers vs. creating a single function/file per handler?
@Frank I guess I should double-check this as well - does the KinesisStream construct also automatically create functions for its listed consumers?
c
Thanks @Michael Clifford
f
@Clayton yeah functions are automatically created for KinesisStream consumers. All SST constructs have the same behavior.