-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless-ticket-tracker-stack.ts
More file actions
58 lines (51 loc) · 2.06 KB
/
serverless-ticket-tracker-stack.ts
File metadata and controls
58 lines (51 loc) · 2.06 KB
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
58
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import * as apigateway from '@aws-cdk/aws-apigateway'
import * as path from 'path';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import { CfnOutput, Duration } from '@aws-cdk/core';
export class ServerlessTicketTrackerStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const table = new dynamodb.Table(this, 'TicketsTable', {
tableName: 'SttTickets',
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
});
const api = new apigateway.RestApi(this, 'TicketsApi');
const ticket = api.root.addResource('ticket');
const getTicketHandler = new lambda.Function(this, 'GetTicket', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda/tickets-get'),
environment: {
TABLE_NAME: table.tableName
},
timeout: Duration.seconds(30)
});
table.grantReadData(getTicketHandler);
ticket.addMethod('GET', new apigateway.LambdaIntegration(getTicketHandler))
const postTicketHandler = new lambda.Function(this, 'TicketsPost', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda/tickets-post'),
environment: {
TABLE_NAME: table.tableName
},
timeout: Duration.seconds(30)
});
table.grantWriteData(postTicketHandler);
ticket.addMethod('POST', new apigateway.LambdaIntegration(postTicketHandler))
const health = api.root.addResource('health');
const healthCheckHandler = new lambda.Function(this, 'HealthCheck', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda/health-check'),
environment: {
TABLE_NAME: table.tableName
},
timeout: Duration.seconds(30)
});
table.grantReadData(healthCheckHandler);
health.addMethod('GET', new apigateway.LambdaIntegration(healthCheckHandler))
}
}