Experiences with AWS AppSync

Chad Faurie
Bluetrino
Published in
5 min readApr 9, 2020

A bit of Background

We are currently building a new platform for a new client of ours and we have tasked ourselves with building a mobile app to test out how our platform handles certain Use Cases.

The basic idea is that a user can request to perform a monetary transaction and another user will need to approve it to complete the request.

So here goes nothing…

AWS AppSync is a managed GraphQL service which links to DynamoDB and AWS ElasticSearch Service.

I have recently started building an App using Expo.io, React Native, GraphQL, AWS Amplify and Cognito as I needed to prototype something quickly as a proof of concept

At Codeworkshop.io we have used Expo.io before with the GoRhino Project which was quite some time ago so I have a bit of experience with React Native, but this was in the time where hooks did not exist.

So for starters I am going to break down my stack

  • Expo.io — Framework that Wraps React Native and provides Linking to React Native Modules
  • React Native — Development Framework leveraging React for Cross Platform Mobile Apps
  • AWS Amplify — Wrapper for common AWS functions, works on both mobile and web (Includes Authentication against Cognito, Federated login Wrappers, API Wrappers, Logging, Analytics, Storage -Based on S3 and more)
  • AWS AppSync — Managed Graphql Service
  • DynamoDb — Managed NoSQL database
  • Terraform — Infrastructure as Code

Having done quite a bit of react development expo is an easy transition

I found jumping into Expo quite easy, there are a few caveats that one needs to be aware of like you have to use React Native Components ‘div’s do not exist!

I found the new Web Builds to be really useful for quick prototyping rather than spinning up an emulator or struggling with my device on the local network to get the Expo app to work (LAN seems to work sometimes, Tunnels always work but your device needs to make a round trip to the internet)

AWS Amplify

AWS amplify provides a Higher Order Component for Authentication, I found it quite buggy with the web view so just keep that in mind if you do intend on testing with the default login screens

AWS Amplify quickly integrates my APIs (Graphql) and Cognito User pools allowing me to call my AppSync backend

AWS Amplify provides a basic GraphQL client, this provides querying and mutation but not much else. I will probably move over to Apollo at a later stage as it provides a lot more features. There are a few caveats here though, I have struggled (in the past) to get the AWS SDK to integrate properly with the new Apollo hooks. The AWS SDK is required for subscriptions and in turn had to revert to using an older version of Apollo with HOCs for this functionality.

AWS AppSync

AppSync is great for short running cloud tasks, there are timeouts and limits to the length of time queries and mutations can run for.

The resolvers are a place where you can get your hands dirty implementing business logic into your ‘Code’

I did find the syntax quite strange as I did need to do some more complex stuff like setting timestamps but once you get into it, it is fairly straight forward and most of the time is inline with DynamoDb operations

Another interesting thing I found was AppSync Resolver Pipelines, they allow you to chain together multiple resolver functions to create a larger set of business logic rules.

For instance you could fetch data from DynamoDb, pass it to an API and return the response to your app in a single GraphQL Query/Mutation

After playing with AppSync, I found that enabling verbose logging helps tremendously with debugging HTTP requests to other APIs, giving you visibility into the full payloads being passed back and forward.

AWS AppSync Settings

The X Ray integration into AppSync is quite interesting especially when visualised in ServiceLens (Both my Public API and AppSync reside in the same account) giving me the ability to trace requests all the way through to my API.

Terraform

Terraform has been my tool of choice for Infrastructure as Code, and I have been using it for quite some time within AWS, having built ML data ingestion pipelines and multiple App infrastructure platforms I strongly believe it is the way to go.

It is a single source of the truth and can be pushed into CI/CD pipelines for automation.

In the case of AppSync I found that the GUI is a bit clumsy and I have no way to version my Endpoint, so I scripted it all out into Terraform and then I use the GUI to run experiments and make alterations quickly so that I can get instant feedback from my app. It also helps that my GraphQL Schema is now stored in our Git Repos so I do not have to worry about accidentally deleting logic

Bonus: X-Ray and ServiceLens

When starting out with AWS a few years back I honestly had no idea what X-Ray was for. I only realised that in distributed systems like micro-services you need a separate system to trace requests flying between all these services. At this time I used a tool called Jaeger for my investigation.

Tracing is great especially in a distributed system, it shows you metrics on requests and response time from various AWS service and you can hunt down bottlenecks and provide additional resources.

X-Ray now has a new service bolted on-top of it called ServiceLens, this was a game changer for me as it combines together both my tracing and logs in one place if you managed to do the configuration right.

Wrapping Up

With all these components I had something of a working prototype of an app up and running in a very short timespan

I learnt a few lessons from the experience, and I definitely would like a fuller GraphQL client in future, I find it quite easy creating my schema in AWS AppSync with DynamoDB, though the learning curve here for newcomers will be quite steep, mainly because DynamoDB is nothing like a traditional SQL database.

Expo is great as long as you don’t have to export for a feature like bluetooth, I have read that the setup alone is not for the faint of heart.

All in all, depending on the use case, the stack I chose definitely gave me an edge in terms of speed to create the proof of concept app.

If you have any questions, check us out at https://bluetrino.com

--

--