-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy paththe-single-purpose-function-stack.ts
45 lines (36 loc) · 1.63 KB
/
the-single-purpose-function-stack.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
import * as cdk from '@aws-cdk/core';
import lambda = require('@aws-cdk/aws-lambda');
import apigw = require('@aws-cdk/aws-apigateway');
export class TheSinglePurposeFunctionStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
/**
* Lambdas defined individually, each handler is in individual file
*/
const addLambda = new lambda.Function(this, 'addLambdaHandler', {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset('lambda-fns/single-purpose-function'),
handler: 'add.handler',
});
const subtractLambda = new lambda.Function(this, 'subtractLambdaHandler', {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset('lambda-fns/single-purpose-function'),
handler: 'subtract.handler',
});
const multiplyLambda = new lambda.Function(this, 'multiplyLambdaHandler', {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset('lambda-fns/single-purpose-function'),
handler: 'multiply.handler',
});
/**
* Routes defined individually on API Gateway
*/
let gateway = new apigw.LambdaRestApi(this, 'SinglePurposeFunctionAPI', {
handler: addLambda,
proxy: false
});
gateway.root.resourceForPath('add').addMethod('GET', new apigw.LambdaIntegration(addLambda));
gateway.root.resourceForPath('subtract').addMethod('GET', new apigw.LambdaIntegration(subtractLambda));
gateway.root.resourceForPath('multiply').addMethod('GET', new apigw.LambdaIntegration(multiplyLambda));
}
}