Presentation for GraphQL Wroclaw #2. Presented on 7th May 2019. Available on: https://www.facebook.com/mirumeelabs/videos/496722830863869/
Serverless is one of the hottest architectural patterns for developing cloud-native applications. GraphQL is rapidly becoming a standard for creating APIs in this environment. The AWS AppSync GraphQL service is a great way to get started with GraphQL in a serverless environment. During this presentation, you will learn how to create serverless GraphQL API applications based on this technology using cloud services like DynamoDB, Elasticsearch, Lambda and Cloudformation.
2. Agenda
Plan
What is AppSync?
What can you use it for?
What is it made of?
AWS AppSync types
Subscriptions
Security
Monitoring and logging
Pricing
Demo - existing data sources
Final thoughts
How to prototype really fast
2
3. What is AppSync?
AWS service that enables developers to easily build products
based on GraphQL.
Out of the box it supports many AWS products including:
● data storages
● lambdas
● cloud security
1
3
10. Types
◦ ID
◦ String
◦ Int
◦ Float
◦ Boolean
◦ AWSDate
◦ AWSTime
◦ AWSDateTime
◦ AWSTimestamp
◦ AWSEmail - Valid RFC 822
◦ AWSJSON - Valid RFC 8259
◦ AWSURL - Valid URL
◦ AWSPhone - Valid phone number (no spec in docs)
◦ AWSIPAddress - Valid IPv4 or IPv6
10
11. Types
AppSync supports interfaces and unions.
The caveat here is that you have to do is to append
‘__typename’ for type resolution
#foreach ($result in $context.result)
## Extract type name from the id field.
#set( $typeName = $result.id.split("-")[0] )
#set( $ignore = $result.put("__typename", $typeName))
#end
$util.toJson($context.result)
11
13. Usually in GraphQL:
Responsible for serving requested data by field.
In AppSync:
Transforming request to data source request
and mapping data source response.
Resolvers
13
14. Unit resolver performs single operation on data
source.
It can also be a batch operation. But not for all
data sources. Supports DynamoDB and
Lambda.
Unit resolver
14
15. Allows executing
multiple operations
against one or more
data sources.
Composed of a list of
functions. Each
function is executed
in sequence and can
execute a single
operation on a data
source.
Pipeline resolver
15
16. Example use cases
◦ Load and transform fields based on the
requested format
◦ Custom roles setup application
Pipeline resolver
16
17. ◦ $ctx.stash
◦ $ctx.prev.result
◦ #return(data: Object) - breaks mapping template
with data
◦ $util.error - breaks execution with error
◦ $util.appendError - marks error without
interruption
Pipeline utilities
17
18. Functions are single operations for redundant
logic on the GraphQL Proxy as a part of
pipeline resolvers.
It can be our customer role check from previous
section
Functions
18
21. Subscription at scale for datasources not
supporting this feature.
AWS takes heavy-lifting and after successful
mutation it pushes notification to all subscribers
for you.
Subscriptions
21
28. We have 3 metrics:
◦ 4xx
◦ 5xx
◦ Latency - processing in ms
Monitoring
28
29. ◦ Request level
▫ Request and response HTTP headers
▫ GraphQL query
▫ Execution summary
▫ GraphQL subscriptions
◦ Field level
▫ Generated Request Mapping with source
and arguments for each field
▫ The transformed Response Mapping for
each field, which includes the data as a
result of resolving that field
▫ Tracing information for each field
Logging
29
30. There are 3 logging levels available:
◦ NONE - No field-level logs are captured
◦ ERROR - Logs fields that are in error
◦ ALL - The following information is logged for all
fields in the query:
▫ Field-level tracing information
▫ Request/response functions that got
resolved for each field
Logging levels
30
32. CRUD
◦ 250k FREE
◦ $4 per million Query and Data Modification
Operations
+
Data transfer fee charged at EC2 data
transfer rates
COSTS BY AWS DOCS
32
33. Real-time updates
◦ 250k FREE
◦ 600k connection minutes FREE
◦ $2 per million Real-time updates
Which are priced per 5kb payload of data
delivered. For example, an 8-KB payload is
metered as two real-time updates.
◦ $0.08 per million minutes of connection to
the AWS AppSync service
COSTS BY AWS DOCS
33
34. ◦ 2500 monthly active real-time app users
▫ 25 hours monthly / user
▫ 1000 sent & received events monthly / user
◦ Total cost
▫ Requests - sent messages:
2500 x 1000 x 4$/1M = 10$
▫ Connectivity:
2500 x 1500 x 0.08$ = 0.3$
▫ Data transfer:
1KB x 2.5M = 2.5 MKB = 2.4GB x 0.09$ = 0.21$
▫ Real-time updates:
2500 x 1000 x 2$/1M = 5$
▫ Total:
15.51$
Pricing example
34
36. Our case
Routes on Elasticsearch -> Take a look
Price service on API Gateway -> Take a look
Airports on DynamoDB -> Take a look
36
Thumbnail URL generator -> Take a look
41. CREDITS
Special thanks to all the people who made and
released these awesome resources for free:
◦ Presentation template by SlidesCarnival
◦ Photographs by Unsplash
41