forked from michalkvasnicak/aws-lambda-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation.yml
152 lines (143 loc) · 4.52 KB
/
cloudformation.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
AWSTemplateFormatVersion: 2010-09-09
Description: Chat example server
Transform: AWS::Serverless-2016-10-31
Resources:
ConnectionsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
# see DynamoDBConnectionManager
TableName: Connections
AttributeDefinitions:
- AttributeName: id
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
# connection id
- AttributeName: id
KeyType: HASH
SubscriptionsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
# see DynamoDBSubscriptionManager
TableName: Subscriptions
AttributeDefinitions:
- AttributeName: event
AttributeType: S
- AttributeName: subscriptionId
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: event
KeyType: HASH
- AttributeName: subscriptionId
KeyType: RANGE
SubscriptionOperationsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
# see DynamoDBSubscriptionManager
TableName: Subscriptions
AttributeDefinitions:
- AttributeName: subscriptionId
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: subscriptionId
KeyType: HASH
EventsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
# see DynamoDBEventStore
TableName: Events
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
# see ISubscriptionEvent
AttributeDefinitions:
- AttributeName: id
AttributeType: S
StreamSpecification:
StreamViewType: NEW_IMAGE
ServerFunction:
# server handler function
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist
FunctionName: chat-example-server
Handler: index.handler
MemorySize: 512
Runtime: nodejs8.10
Tags:
Project: serverless-chat-example
Timeout: 6
Policies:
- AWSLambdaExecute # Managed Policy
- Version: '2012-10-17' # Policy Document
Statement:
# AWS Api Gateway manager permission (we need this to be able to send events to clients)
- Effect: Allow
Action:
- execute-api:ManageConnections
Resource: 'arn:aws:execute-api:*:*:*/development/POST/@connections/*'
- Effect: Allow
Action:
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
Resource: !GetAtt ConnectionsDynamoDBTable.Arn
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource: !GetAtt EventsDynamoDBTable.StreamArn
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: !GetAtt EventsDynamoDBTable.Arn
- Effect: Allow
Action:
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:Scan
Resource: !GetAtt SubscriptionsDynamoDBTable.Arn
- Effect: Allow
Action:
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:PutItem
Resource: !GetAtt SubscriptionOperationsDynamoDBTable.Arn
# attach event sources
Events:
HTTPEndpoint:
Type: Api
Properties:
Path: /
Method: POST
DynamoDBEventStream:
Type: DynamoDB
Properties:
Stream: !GetAtt EventsDynamoDBTable.StreamArn
StartingPosition: LATEST
BatchSize: 100
Outputs:
ConnectionsTableARN:
Description: 'DynamoDB connections table ARN'
Value: !GetAtt ConnectionsDynamoDBTable.Arn
EventsTableARN:
Description: 'DynamoDB events table ARN'
Value: !GetAtt EventsDynamoDBTable.Arn
EventsTableStreamARN:
Description: 'DynamoDB events table ARN'
Value: !GetAtt EventsDynamoDBTable.StreamArn
SubscriptionsTableARN:
Description: 'DynamoDB subscriptions table ARN'
Value: !GetAtt SubscriptionsDynamoDBTable.Arn
ServerFunctionARN:
Description: 'Server function ARN'
Value: !GetAtt ServerFunction.Arn