import {App, http, Opts, Resource, Post, Get} from '../src/app'; import HttpServer, {MockServer} from '../src/server'; import Hapi from 'hapi'; /** * An application extends the service container * And exposes a set of methods for registering 'handlers'. * Handlers can be Lambda functions, http handlers, or GraphQL resolvers. * * These handlers are registered as part of the service container, which you can then * use to run locally, or deploy, depending on the methods called, and the decorators applied. * * For example, you could create an application with several lambdas, using the 'http' decorator. * * Under the hood, Yantra (code name), will utilise ais service discovery to bridge the gap between services, * and logic within this application. * * Because Yantra uses AWS CDK, you don't need to worry about permissions, these are handled in the most * secure way possible, because CDK will choose the most restrictive permissions possible, based on then * interlinking of your defined infrastructure. I.e, this will work out of the box, and will be optimally secure. * * app.run() will run the service locally * app.deploy() will run through the container for an infrastructure stack, and deploy it. */ @Resource("messages") class MyApp extends App { public init() { this.getMessage(); } // Creates an api gateway path with the registered handler // /messages/{id} @Get({ path: "/{id}" }) getMessage() { return this.registerHandler('get-message', 'example/handlers/'); } // Subscribes to SNS topics fired in other services // @subscribe([ // "ais-latest.tenant.onTenantCreated", // "ais-latest.tenant.onNewUser", // ]) // sendEmail() { // this.container.registerHandler('send-email', 'send-email/index.handler'); // } // @listen([ // "ais-latest.feeds.stream", // ]) // processFeedItem() { // this.registerHandler('feed-item', 'feed-item/index.handler'); // } } const app = new MyApp(new HttpServer(new Hapi.Server({ host: '0.0.0.0', port: 9898 })), { type: 'http', service: 'my-app', stage: 'latest', region: 'eu-west-1', }); app.init(); app.deploy(); // app.run().then(console.info).catch(console.error); // Unfortunately, we still have to use the AWS CDK CLI, we can't do that programmatically, yet...