Replies: 1 comment 11 replies
-
Hello @ygyg70
Has I explained on slack:
Your approach seems to be different from the Serverless tutorial https://tsed.io/tutorials/serverless.html#configuration This is clearly not ideal and efficient. Your proposition seems to be more interesting but there is not example for that. The main idea is to have on handler/aws lambda that invoke the Ts.ED DI (https://github.com/tsedio/tsed/tree/production/packages/di): my-handler.ts import {InjectorService, attachLogger, DIContext} from "@tsed/di";
import {$log} from "@tsed/logger";
import {MyService} from "../usecases/MyService";
async function bootstrap(Service) {
const injector = new InjectorService();
// configure the default logger
attachLogger(injector, $log);
// Load all providers registered via @Injectable decorator
await injector.load();
// emit event to trigger actions for third parties modules
await injector.emit("$onReady");
return injector
}
const promise = bootstrap(); // to pre build Container before lambda handler invokation
export default async function handler(awsArgs) { // need to be completed
const injector = await promise
const ctx = new DIContext({
id: /* aws request.id || */ uuid.v4(),
injector,
logger: injector.logger
})
ctx.set("aws_args", awsArgs) // customise that to you convenient
const myService = injector.get<MyService>(MyService);
// we need to map aws Args to keep our MyService agnostic from AWS /!\ important
// and to reuse MyService inside a Ts.ED controller (clean architecture)
const {value, other} = mapAwsArg(AwsArgs);
try {
const response = await runInContext(ctx, () => myService.doSomething(value, other));
return mapResponseToAws(response)
} catch(er) {
// handle response
}
} Tell me if you have some question ;) |
Beta Was this translation helpful? Give feedback.
-
Before creating my own build configuration (probably something like), I wanted to ask if there is already something out there I can use.
(or perhaps someone is kind enough to share their approach)
Any help appreciated!
Beta Was this translation helpful? Give feedback.
All reactions