Akos
03/10/2021, 3:45 PMSeth Geoghegan
03/10/2021, 4:45 PM// Create the HTTP API
const api = new sst.Api(this, "Api", {
routes: {
"GET /notes": "src/myLambda.main",
"POST /notes": "src/myLambda.main",
"OPTIONS /notes": "src/myLambda.main"
}
});
Akos
03/10/2021, 4:48 PMAkos
03/10/2021, 4:50 PMSeth Geoghegan
03/10/2021, 4:50 PMAkos
03/10/2021, 4:50 PMdefaultFunctionProps
Akos
03/10/2021, 5:03 PMdefaultFunctionProps
(even when I'd expect it to apply to the other ones that the API construct creates):
Error: Cannot define defaultFunctionProps when a Function is passed in to the routes
at Api.addRoute (<redacted>/node_modules/@serverless-stack/resources/src/Api.ts:494:15)
at <redacted>/node_modules/@serverless-stack/resources/src/Api.ts:401:23
at Array.forEach (<anonymous>)
at Api.addRoutes (<redacted>/node_modules/@serverless-stack/resources/src/Api.ts:399:25)
at new Api (<redacted>/node_modules/@serverless-stack/resources/src/Api.ts:171:10)
at new ApiStack (<redacted>/lib/ApiStack.ts:44:17)
at Object.main (<redacted>/lib/index.ts:9:3)
at Object.<anonymous> (<redacted>/.build/run.js:64:16)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
Akos
03/10/2021, 5:05 PMdefaultFunctionProps
only applying to a subset of functions is probably more confusing than just throwing an error.Akos
03/10/2021, 5:07 PMApi
construct and do the defaulting myself, something like:
const defaultFunctionProps: sst.FunctionProps = {
reservedConcurrentExecutions: env.lambda.concurrencyLimit,
timeout: env.lambda.timeoutSeconds,
runtime: lambda.Runtime.NODEJS_14_X,
};
const graphqlLambda = new sst.Function(this, 'graphql-api', {
...defaultFunctionProps,
handler: 'services/graphql-api/src/main.handler',
environment: {
...databaseEnvironmentVariables,
},
});
Mike McCall
03/10/2021, 6:03 PMFrank
defaultFunctionProps
when passing in an `sst.Function`; or
2. Allow multiple routes handled by the same function
routes: {
"GET /notes": "src/notes.main",
"POST /notes": sst.ApiRoute.INHERIT_ABOVE,
"GET /users": "src/users.main",
}
Frank
Frank
Akos
03/11/2021, 8:55 AM