-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
86 lines (81 loc) · 2.24 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: GraphQL APIs for my personal blog.
Globals:
Function:
Runtime: nodejs8.10
Timeout: 30
Environment:
Variables:
TABLE_NAME: blogs
LAMBDA_AWS_REGION: ap-southeast-1
Api:
Cors:
AllowHeaders: "'Content-Type, X-Experience-API-Version,Authorization'"
AllowMethods: "'*'"
AllowOrigin: "'*'"
Resources:
# create a custom handler to return 200 and appropriate headers for your OPTIONS requests
# OptionsFunction:
# Type: AWS::Serverless::Function
# Properties:
# FunctionName: options-handler
# Handler: index.options #nodejs
# Events:
# Options:
# Type: Api
# Properties:
# Path: /{cors+}
# Method: OPTIONS
# Auth:
# Authorizer: NONE
GraphqlFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.graphqlHandler
FunctionName: GraphqlFunction
Policies: AmazonDynamoDBFullAccess
Events:
PostResource:
Type: Api
Properties:
Path: /graphql
Method: post
CommentTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: blog-comments
AttributeDefinitions:
- AttributeName: blogId
AttributeType: S
- AttributeName: commentId
AttributeType: S
KeySchema:
- AttributeName: blogId
KeyType: HASH
- AttributeName: commentId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
ViewTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: blog-views
AttributeDefinitions:
- AttributeName: blogId
AttributeType: S
- AttributeName: viewAt
AttributeType: S
KeySchema:
- AttributeName: blogId
KeyType: HASH
- AttributeName: viewAt
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Outputs:
ApiUrl:
Description: URL of the Prod stage of the API endpoint
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"