1629382620
Yesterday at reInvent, Amazon launched AppSync, a new GraphQL service featuring real-time updates and built-in offline support. Managed in the AWS console, AppSync’s GraphQL layer aggregates data from other AWS products such as ElasticSearch and DynamoDB. In your application, you query your GraphQL API with the AppSync Client, available for web and native.
1599105420
AppSync is a managed GraphQL service offered by Amazon Web Services and can be used to build scalable enterprise APIs. A typical AppSync solution consists of small resolvers that can be combined to access various data sources such as databases, HTTP APIs or AWS Lambda.
In this example, I will be talking about using AWS AppSync with AWS Lambda data sources and one of the challenges I have come across while developing enterprise scale solutions with these technologies.
Each Lambda resolver you have in a particular request triggers an invocation. The problem comes with having nested resolvers where you only request data from the nested Lambda rather than the parent Lambda. As a result you will cause several invocations, incur cost and resource for the first Lambda without needing to.
If you’re running enterprise serverless it is important to consider the architecture to reduce the amount of compute where possible and lower the risk of hitting limits imposed by AWS.
Thankfully, AWS released an AppSync update in Feb 2020 giving us access to the context info object so we can mitigate this issue. Read more here.
Say you have a GraphQL endpoint and schema to retrieve a typical blog post:
type Post{
id: ID!
title: String!
content: String!
image: ImageData!
}
type ImageData{
id: ID!
postId: ID!
path: String!
tags: String
}
type Query{
getPost(id: ID!): Post!
}
Using GraphQL, your query could look like:
query GetPost{
getPost(id: $id){
title
content
image{
path
tags
}
}
}
#aws-appsync #graphql #aws-lambda #serverless #aws
1596762420
Today, I’m going to walk you through using AppSync’s Direct Lambda feature. I built the thing during my internship this Summer after all, so I should be able to express how simple, yet effective, this feature is in allowing you to configure Lambdas for your API on AppSync.
_Go ahead and jump to the section labelled __Let there be an API! _if you’d like to skip the bits about what the old workflow for a Lambda resolver was like.
I’d first like to make a point about why Direct Lambdas were necessary. Here’s a picture to help demonstrate that point.
VTL? Cancelled, sorta. Call the mob.
In order to set up a Lambda resolver for a field on AppSync, you’d first have to check out the resolver mapping template reference, then you’d have to set up your mapping templates in a language called VTL. These templates translate data back and forth between your Lambda. Finally, you’d be able to set up your Lambda to expect the data as translated by the mapping templates.
Notice that I mentioned that you had to write code in two separate places: the Lambda and the mapping templates, which might be in the Appsync console editors, uploaded through the SDK, or in a CloudFormation template. This introduces unnecessary coupling between your Lambda code and your mapping templates, which is probably not optimal for your code-base, nor your mental health.
This is where the problem lies: if it’s at all complicated, then it’s too complicated. The goal is to think less… Er, less about things that don’t matter, that is.
If only there was an easier way to configure a Lambda resolver on AppSync. If only there was a way to write less code and get more done.
There is now a way, Direct Lambdas.
This is probably how things work under the hood.
I’d like to avoid making this tutorial dry and boring so I’ve decided that our API will be all about awesome, original, definitely-not-cringe dad jokes! Plus, we can utilize a friendly API called icanhazdadjokes that offers an unprecedented collection of definitely-not-cringe-worthy dad jokes for free. That’s a low price!
Let’s start off with a specification of what our API should do. I’d like to create an API that will allows a client to either get a random Joke or get a Joke specified by an ID.
Here’s how the entire thing will work:
#aws #graphql #serverless #aws-lambda #aws-appsync
1625819340
The AWS Amplify CLI toolchain now automatically generates your GraphQL queries, mutations, & subscriptions as well as a typed API file containing your Schema. In this video, we walk through how to use it.
https://aws-amplify.github.io/
#graphql #aws appsync #aws amplify #codegen
1625815680
In this video, we walk through how to create a new AWS AppSync GraphQL API & connect to it from a client-side application.
#aws amplify #aws appsync #graphql
1625834400
In this video we’ll build a Game of Thrones app using AWS AppSync & the Gatsby Source GraphQL plugin. We’ll learn how to create the GraphQL api, install & configure Gatsby Source GraphQL, & deploy the app with the static GraphQL data available to render in the app.
#aws appsync #aws amplify #graphql