-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserverless.yml
executable file
·156 lines (148 loc) · 5.12 KB
/
serverless.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
153
154
155
156
service: serverless-graphql-appsync-rds
frameworkVersion: ">=1.21.0 <2.0.0"
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: xx-xxxx-x
profile: default
environment:
NODE_ENV: ${self:provider.stage}
DATABASE_URL_DEV: xxxxxxxxxxxxx
DATABASE_USER_DEV: xxxxxxxxxxxxx
DATABASE_PASSWORD_DEV: xxxxxxxxxxxxx
DATABASE_NAME_DEV: posts
plugins:
- serverless-appsync-plugin
- serverless-offline
- serverless-webpack
custom:
accountId: xxxxxxxxxxxx
webpackIncludeModules: true
appSync:
name: ${self:service}-${self:provider.stage}
authenticationType: API_KEY
mappingTemplates:
# Query mapping templates
- dataSource: Lambda
type: Query
field: getAuthor
request: "getAuthor-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Query
field: getAuthors
request: "getAuthors-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Query
field: getPost
request: "getPost-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Query
field: getPosts
request: "getPosts-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Query
field: getComment
request: "getComment-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Query
field: getComments
request: "getComments-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
# Mutation mapping templates
- dataSource: Lambda
type: Mutation
field: addPost
request: "addPost-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Mutation
field: updatePost
request: "updatePost-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Mutation
field: deletePost
request: "deletePost-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Mutation
field: addComment
request: "addComment-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Mutation
field: updateComment
request: "updateComment-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Mutation
field: deleteComment
request: "deleteComment-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
# Type mapping templates
- dataSource: Lambda
type: Author
field: posts
request: "authorPosts-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Post
field: comments
request: "postComments-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Post
field: author
request: "postAuthor-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
- dataSource: Lambda
type: Comment
field: author
request: "commentAuthor-request-mapping-template.txt"
response: "generic-response-mapping-template.txt"
serviceRole: "AppSyncServiceRole"
dataSources:
- type: AWS_LAMBDA
name: Lambda
description: 'Lambda DataSource'
config:
lambdaFunctionArn: "arn:aws:lambda:${self:provider.region}:${self:custom.accountId}:function:${self:service}-${self:provider.stage}-graphql"
serviceRoleArn: "arn:aws:iam::${self:custom.accountId}:role/${self:custom.appSync.serviceRole}"
functions:
graphql:
handler: handler.graphqlHandler
resources:
Resources:
AppSyncServiceRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: "AppSyncServiceRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "appsync.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
-
PolicyName: "AppSyncServiceRole-Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "lambda:invokeFunction"
Resource:
- "arn:aws:lambda:${self:provider.region}:*:function:${self:service}-${self:provider.stage}-graphql"
- "arn:aws:lambda:${self:provider.region}:*:function:${self:service}-${self:provider.stage}-graphql:*"