title: Is Appsync/GraphQL a good solution for real-time display of reduced S3-based time series data?
body: <p>I have JSON files containing time series sample data being fed into S3. I have a React client with a component that needs to show an up-to-date statistical average of the sample data from the last x minutes. </p>
  
  <p>Ideally the updates would be triggered by S3 upload rather than the browser needing to poll a webservice. Websockets and Server Sent Events are not an option. Can I practically use AWS Appsync's subscriptions to provide real-time data, given these requirements?</p>
  
  <p>I'm not opposed to using an intermediary database if needed. I assume it will be beneficial for the step of querying data for a time range to calculate the average, and I assume I would trigger Lambda with S3 and use it to pull the S3 object data into the DB. </p>
  
  <p>Amazon announced the addition of <a href="https://aws.amazon.com/blogs/mobile/new-aws-appsync-features-and-whitelist-removal/" rel="nofollow noreferrer">Local Resolvers</a> in February</p>
  
  <blockquote>
    <p>For example, a Lambda function could invoke GraphQL mutations to AWS AppSync in response to some event that takes place, such as processing data that’s uploaded to an S3 bucket</p>
  </blockquote>
  
  <p>That sounds promising except I can't find any examples involving Local Resolvers and Lambda/S3. The only documentation I could find is <a href="https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-local-resolvers.html" rel="nofollow noreferrer">here</a>. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Having done some reading on GraphQL I learned about the API and it seems I should be able to use an HTTP client in lambda to do mutations. Tried this with curl and it worked:</p>
  
  <pre><code>curl -X POST \
     https://censored.appsync-api.us-east-1.amazonaws.com/graphql \
     -H 'Content-Type: application/json' \
     -H 'x-api-key: censored' \
     -d '{"query": "mutation CreateEvent {createEvent(name: \"testName\", when: \"Now\", where: \"here\", description: \"testDescription\") {name when where description}}"}'
  </code></pre>
  
  <p>With this I figure I can now call an "addIntervalData" mutation via Lambda to add each S3 object's contents to a database and use a lambda resolver to implement "getAverage" and do the averaging calculation. Seems like a good direction?</p>