-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-world-api.ts
43 lines (34 loc) · 1.19 KB
/
hello-world-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Construct } from "constructs";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as nodejs from "aws-cdk-lib/aws-lambda-nodejs";
import * as apigateway from "aws-cdk-lib/aws-apigatewayv2";
import * as integrations from "aws-cdk-lib/aws-apigatewayv2-integrations";
export interface HelloWorldApiProps {
//
}
export class HelloWorldApi extends Construct {
protected readonly handler: lambda.Function;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(scope: Construct, id: string, _props: HelloWorldApiProps) {
super(scope, id);
// Create lambda handler for hello world response.
const handler = new nodejs.NodejsFunction(this, "Handler", {
entry: "src/hello-world-handler.ts",
});
// Create integration to connect with lambda.
const integration = new integrations.HttpLambdaIntegration(
"HttpLambdaIntegration",
handler,
);
// Create HTTP API.
const api = new apigateway.HttpApi(this, "HttpApi");
// Add hello world integration at root path.
api.addRoutes({
path: "/",
integration,
methods: [apigateway.HttpMethod.GET],
});
// Exports.
this.handler = handler;
}
}