Stan
10/14/2021, 2:39 PMimport { Function } from "@serverless-stack/resources";
import { APIGatewayProxyEventV2, APIGatewayProxyHandlerV2 } from "aws-lambda";
export const lambdaHandler: APIGatewayProxyHandlerV2 = async (event: APIGatewayProxyEventV2) => {
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Your request was received at ${event.requestContext.time}.`
};
};
new Function(this, "MySnsLambda", {
handler: lambdaHandler
});
in the docs I found only this way:
new Function(this, "MySnsLambda", {
handler: "src/sns/index.main",
});
thdxr
10/14/2021, 2:42 PMStan
10/14/2021, 3:36 PMthdxr
10/14/2021, 3:39 PMStan
10/14/2021, 3:55 PMFrank
export class MainStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string) {
super(scope, id, props);
new sst.Function(this, "Fn", {
handler: "./MainStack.lambdaHandler",
});
}
}
export function async lambdaHandler(event: APIGatewayProxyEventV2): APIGatewayProxyHandlerV2 {
...
};
Stan
10/15/2021, 11:18 AMFrank
./MainStack.lambdaHandler
to stacks/MainStack.lambdaHandler
or lib/MainStack.lambdaHandler
wherever ur MainStack.ts isFrank
Jay
Stan
10/18/2021, 5:40 PMFrank
Interesting structure (I know @thdxr would love to see this). I’ve thought about this way of setting up monorepo, where both stack files and lambda files sits in the services folder. I’m curious to hear about ur experience as you add more stacks to the app, and if you come across certain benefit or downside with this approach.src/microservices/XXX/XXXStack.ts