-
Notifications
You must be signed in to change notification settings - Fork 3
/
stack.ts
57 lines (49 loc) · 2.11 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as cdk from 'aws-cdk-lib';
import { join } from "path";
export class Part01LambdaStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// Provision a simple Lambda function
new cdk.aws_lambda_nodejs.NodejsFunction(this, 'myFirstLambdaFunction', {
entry: join(__dirname, 'myFirstLambda', 'handler.ts'),
handler: 'handler',
runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
bundling: {
externalModules: ['@aws-sdk'],
},
});
// Provision a new Lambda function
// Put the result inside a variable so we can use it later
const rollADiceFunction = new cdk.aws_lambda_nodejs.NodejsFunction(this, 'rollADiceFunction', {
entry: join(__dirname, 'rollADice', 'handler.ts'),
handler: 'handler',
runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
bundling: {
externalModules: ['@aws-sdk'],
},
});
// Provision a new REST API Gateway
const myFirstApi = new cdk.aws_apigateway.RestApi(this, 'myFirstApi', {
restApiName: 'Part01Service',
});
// Add a new GET /dice resource to the API Gateway
// Corresponding to the invocation of the rollADice function
const diceResource = myFirstApi.root.addResource('dice');
diceResource.addMethod('GET', new cdk.aws_apigateway.LambdaIntegration(rollADiceFunction));
// Provision a new Lambda function
// Put the result inside a variable so we can use it later
const rollDicesFunction = new cdk.aws_lambda_nodejs.NodejsFunction(this, 'rollDicesFunction', {
entry: join(__dirname, 'rollManyDices', 'handler.ts'),
handler: 'handler',
runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
bundling: {
externalModules: ['@aws-sdk'],
},
});
// Add a new GET /dice/:nbOfDices resource to the API Gateway
// Corresponding to the invocation of the rollManyDices function
diceResource.addResource('{nbOfDices}').addMethod('GET', new cdk.aws_apigateway.LambdaIntegration(rollDicesFunction));
}
}