-
Notifications
You must be signed in to change notification settings - Fork 18
/
template.yaml
91 lines (85 loc) · 2.57 KB
/
template.yaml
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: AppSync Broadcaster
Metadata:
AWS::ServerlessRepo::Application:
Name: appsync-broadcaster
Description: Simple app that broadcasts messages to multiple clients using Serverless GraphQL real-time subscriptions powered by AWS AppSync
Author: awsed
SpdxLicenseId: MIT
LicenseUrl: LICENSE.txt
ReadmeUrl: README.md
Labels: ['appsync', 'graphql', 'real-time', 'react', 'amplify']
HomepageUrl: https://github.com/awsed/appsync-broadcaster-sar
SemanticVersion: 1.0.0
SourceCodeUrl: https://github.com/awsed/appsync-broadcaster-sar
Outputs:
ApiId:
Description: Unique AWS AppSync GraphQL API Identifier
Value: !GetAtt broadcasterApi.ApiId
ApiUrl:
Description: The Endpoint URL of your GraphQL API
Value: !GetAtt broadcasterApi.GraphQLUrl
Region:
Description: Region where the resources are deployed
Value: !Ref AWS::Region
ApiKey:
Description: The API Key to access your API
Value: !GetAtt apiKey.ApiKey
Resources:
broadcasterApi:
Type: "AWS::AppSync::GraphQLApi"
Properties:
Name: "BroadcasterSAR"
AuthenticationType: "API_KEY"
apiKey:
Type: "AWS::AppSync::ApiKey"
Properties:
ApiId: !GetAtt broadcasterApi.ApiId
pubSubDataSource:
Type: "AWS::AppSync::DataSource"
Properties:
Type: NONE
Description: "Local Resolver"
ApiId: !GetAtt broadcasterApi.ApiId
Name: PubSub
schema:
Type: "AWS::AppSync::GraphQLSchema"
Properties:
ApiId: !GetAtt broadcasterApi.ApiId
Definition: |
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
type Message {
message: String!
}
type Mutation {
sendMessage(message: String!): Message
}
type Query {
getMessage: Message
}
type Subscription {
subscribeToMessage: Message
@aws_subscribe(mutations: ["sendMessage"])
}
pubSubResolver:
Type: "AWS::AppSync::Resolver"
Properties:
ApiId: !GetAtt broadcasterApi.ApiId
TypeName: "Mutation"
FieldName: "sendMessage"
DataSourceName: !GetAtt pubSubDataSource.Name
RequestMappingTemplate: |
{
"version": "2017-02-28",
"payload": {
"message": "${context.arguments.message}",
"sentAt": "$util.time.nowISO8601()"
}
}
ResponseMappingTemplate: |
$util.toJson($context.result)