-
Notifications
You must be signed in to change notification settings - Fork 14
/
template.yml
109 lines (95 loc) · 3.2 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
Lambda:
Type: AWS::Serverless::Function
Properties:
Handler: dist/handler_linux
Runtime: go1.x
Tracing: Active
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: appsync.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: allow-access-to-lambda-from-appsync
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: lambda:invokeFunction
Resource:
- !GetAtt [ Lambda, Arn ]
- !Join [ '', [ !GetAtt [ Lambda, Arn ], ':*' ] ]
AppSyncAPI:
Type: AWS::AppSync::GraphQLApi
Properties:
Name: !Join [ -, [ !Ref ParamProjectName, !Ref ParamENV ] ]
AuthenticationType: API_KEY
AppSyncSchema:
Type: AWS::AppSync::GraphQLSchema
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
DefinitionS3Location: schema.graphql
AppSyncDataSource:
Type: AWS::AppSync::DataSource
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
Name: handler
Type: AWS_LAMBDA
LambdaConfig:
LambdaFunctionArn: !GetAtt [ Lambda, Arn ]
ServiceRoleArn: !GetAtt [ Role, Arn ]
AppSyncResolverPeople:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
TypeName: Query
FieldName: people
DataSourceName: !GetAtt [ AppSyncDataSource, Name ]
RequestMappingTemplate: '{ "version" : "2017-02-28", "operation": "Invoke", "payload": { "resolve": "query.people", "context": $utils.toJson($context) } }'
ResponseMappingTemplate: $util.toJson($context.result)
AppSyncResolverPerson:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
TypeName: Query
FieldName: person
DataSourceName: !GetAtt [ AppSyncDataSource, Name ]
RequestMappingTemplate: '{ "version" : "2017-02-28", "operation": "Invoke", "payload": { "resolve": "query.person", "context": $utils.toJson($context) } }'
ResponseMappingTemplate: $util.toJson($context.result)
AppSyncResolverFriends:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
TypeName: Person
FieldName: friends
DataSourceName: !GetAtt [ AppSyncDataSource, Name ]
RequestMappingTemplate: '{ "version" : "2017-02-28", "operation": "Invoke", "payload": { "resolve": "field.person.friends", "context": $utils.toJson($context) } }'
ResponseMappingTemplate: $util.toJson($context.result)
AppSyncAPIKey:
Type: AWS::AppSync::ApiKey
Properties:
ApiId: !GetAtt [ AppSyncAPI, ApiId ]
Expires: !Ref ParamKeyExpiration
Parameters:
ParamProjectName:
Type: String
ParamENV:
Type: String
ParamKeyExpiration:
Type: Number
Outputs:
APIKey:
Description: API Key
Value: !GetAtt [ AppSyncAPIKey, ApiKey ]
GraphQL:
Description: GraphQL URL
Value: !GetAtt [ AppSyncAPI, GraphQLUrl ]