-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
138 lines (131 loc) · 2.98 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import * as aws from '@pulumi/aws';
import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';
import graphqlCallback from './src/server';
const stackConfig = new pulumi.Config();
const config = {
tableName: stackConfig.require('tableName'),
token: stackConfig.requireSecret('token'),
};
// create a table to point at
new aws.dynamodb.Table(config.tableName, {
name: config.tableName,
attributes: [
{
name: 'hashKey',
type: 'S',
},
{
name: 'id',
type: 'S',
},
{
name: 'name',
type: 'S',
},
{
name: 'updatedAt',
type: 'S',
},
{
name: 'createdAt',
type: 'S',
},
],
globalSecondaryIndexes: [
{
projectionType: 'ALL',
writeCapacity: 5,
readCapacity: 5,
hashKey: 'name',
name: 'name',
},
{
projectionType: 'ALL',
writeCapacity: 5,
readCapacity: 5,
hashKey: 'updatedAt',
name: 'updatedAt',
},
{
projectionType: 'ALL',
writeCapacity: 5,
readCapacity: 5,
hashKey: 'createdAt',
name: 'createdAt',
},
],
hashKey: 'hashKey',
rangeKey: 'id',
readCapacity: 5,
writeCapacity: 5,
});
// some variables used in both types of endpoints
const policies = [
// able to be executed
aws.iam.ManagedPolicies.AWSLambdaVPCAccessExecutionRole,
// need to be able to create and modify the function
aws.iam.ManagedPolicy.LambdaFullAccess,
// this function needs permissions to access that database
aws.iam.ManagedPolicy.AmazonDynamoDBFullAccess,
// to enable complex functionality, we need access to event bridge emissions
'arn:aws:iam::aws:policy/AmazonEventBridgeFullAccess',
];
const variables = {
TOKEN: config.token,
REGION: pulumi.all([aws.getRegion()]).apply(([region]) => region.id),
TABLE_NAME: config.tableName,
};
const handler = new aws.lambda.CallbackFunction('solosis', {
callbackFactory: graphqlCallback,
environment: { variables },
memorySize: 1024,
policies,
} as any);
// Create an API endpoint
const endpoint = new awsx.apigateway.API('solosis', {
routes: [
{
path: '/graphql',
method: 'ANY',
eventHandler: handler,
},
{
path: '/things/{id}',
method: 'POST',
contentType: 'application/json',
eventHandler: handler,
},
{
path: '/things/{id}',
method: 'PUT',
contentType: 'application/json',
eventHandler: handler,
},
{
path: '/things/{id}',
method: 'GET',
contentType: 'application/json',
eventHandler: handler,
},
{
path: '/things/{id}',
method: 'DELETE',
contentType: 'application/json',
eventHandler: handler,
},
{
path: '/things',
method: 'POST',
contentType: 'application/json',
eventHandler: handler,
},
{
path: '/things',
method: 'GET',
contentType: 'application/json',
eventHandler: handler,
},
],
});
exports.endpoint = endpoint.url;