-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapigateway.ts
56 lines (44 loc) · 1.65 KB
/
apigateway.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
44
45
46
47
48
49
50
51
52
53
54
55
56
import { LambdaRestApi } from 'aws-cdk-lib/aws-apigateway';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Construct } from 'constructs';
interface EcomApiGatewayProps {
productMicroservice: NodejsFunction;
basketMicroservice: NodejsFunction;
}
export class EcomApiGateway extends Construct {
constructor(scope: Construct, id: string, props: EcomApiGatewayProps) {
super(scope, id);
this.createProductApi(props.productMicroservice);
this.createBasketApi(props.basketMicroservice);
}
private createProductApi(productMicroservice: NodejsFunction) {
const apiGateWay = new LambdaRestApi(this, 'productAPI', {
restApiName: 'Product Service',
handler: productMicroservice,
proxy: false,
});
const product = apiGateWay.root.addResource('product'); // /product
product.addMethod('GET');
product.addMethod('POST');
const singleProduct = product.addResource('{id}'); // /product/{id}
singleProduct.addMethod('GET');
singleProduct.addMethod('PUT');
singleProduct.addMethod('DELETE');
}
private createBasketApi(basketMicroservice: NodejsFunction) {
const apiGateWay = new LambdaRestApi(this, 'basketAPI', {
restApiName: 'Basket Service',
handler: basketMicroservice,
proxy: false,
});
const basket = apiGateWay.root.addResource('basket'); // /basket
basket.addMethod('GET');
basket.addMethod('POST');
const singleBasket = basket.addResource('{userName}'); // /basket/{userName}
singleBasket.addMethod('GET');
singleBasket.addMethod('PUT');
singleBasket.addMethod('DELETE');
const basketCheckout = basket.addResource('checkout'); // /basket/checkout
basketCheckout.addMethod('POST');
}
}