19

I am looking to dive into a project using AppSync. So far I have been able to find plenty of articles and such online giving all the steps as to what buttons to click in order to get a sample project running, but none of them seem to touch on how one deals with it from a local development or in a CI/CD environment. Its probably my "old school" idea of how dev usually works, but I was expecting some way to simulate enough of the environment locally to do development and run unit tests, but I can't seem to find any way to do just that. And when I get to the UI portion I have no idea how to have a local dev instance of the backend to run against.

Do people not develop in this way anymore, opting to instead stand up a "development stack"? I just want to make sure I am not painting myself into a corner in the future.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • Have you looked into this [local resolver](https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-local-resolvers.html)? You can use it to forward the result of the request mapping template to the response mapping template – Lisa M Shon Aug 10 '18 at 16:32
  • 1
    @LisaMShon I am not sure that's what I am looking for. Basically what I am asking is: How does one develop/test said back-end code when it seems like everything is hosted in remote servers? I am used to the old method of write and test local, check in and then deploy up through test/qa/prod environments. This seems like it's intended that you develop your frontend against a live dev backend? – CodeChimp Aug 11 '18 at 15:27
  • You could set up a separate stack for dev/qa/prod. This way, your development stack and your prod stacks won't interfere. – Lisa M Shon Aug 13 '18 at 05:27
  • 1
    @LisaMShon That's what I think I will end up doing. I was just curious if there were a better way people were doing it that didn't involve standing up a separate remote environment. I was also looking at Local Stack, but it doesn't do AppSync. I guess the other alternative would be to host it locally using a simple Apollo/Express server, but then you loose all the bolted on pieces like authentication/authorization. – CodeChimp Aug 13 '18 at 21:12
  • Maybe you can even use [AWS CodePipeline](https://aws.amazon.com/codepipeline/) to achieve CI/CD – Lisa M Shon Aug 14 '18 at 20:31
  • The thing gets more complicated when working in a team, if you are using CloudFormation for deployment, resolvers (among others resources) get overwritten. And there is a monetary cost for having an instance for each git branch. :( – Raydel Miranda Oct 16 '18 at 16:40
  • 1
    If you use the serverless framework in combination with serverless-appsync and serverless-appsync-offline you could simulate an "offline" environment within the CI. Although I didn't test it yet. – sebastian Oct 27 '18 at 11:07
  • I just want to say, you're not "old school". https://localstack.cloud seem to be aiming to fill that gap, but it looks a while off production ready yet. Amplify cli (if you're using that) has support for environments now, so you can have different dev, test and prod environments. But at this stage, it's still clunky and slow to deploy updates (Several minutes for a code, deploy, test cycle) and only supports some configurations and services. So things seem to be heading in the direction that you are after, but they are taking a while to get there. – Ryan How May 24 '19 at 03:45
  • 1
    I have found in practice MOST of my required testing for AppSync revolves around the VTL templates. I recently uncovered an easy way to do unit testing in Jest, see my other [stackoverflow answer](https://stackoverflow.com/a/63173641/2108798) for an actual example – DaKaZ Jul 30 '20 at 13:04
  • @CodeChimp What has been your experience after a few years ? Have you ended up developing against a live environment or have you used something like LocalStack ? – Starscream Jul 13 '22 at 09:38
  • @Starscream So, at my "real job" we have taken to having a sandbox setup where all things created in the sandbox get destroyed nightly. Devs basically have to run the same "infrastructure as code" CI/CD steps daily to setup their dev environments. It takes a bit to get used to, but seems to be the best option out there, and it seems to make our Devs think about their infrastructure as they are coding. – CodeChimp Aug 11 '22 at 12:44

3 Answers3

3

Short answer is no. Here are your options:

  • AppSync Emulator for Serverless Framework. It's a nice emulator, but still limited and differs quite a bit from the the real API in my opinion.
  • We ended up writing separated unit tests for VTL templates and compare result query to an appropriate fixture. You could deploy full featured VTL Parser on Java but there are simpler solutions: a Python library AirSpeed; for JS you could use one from the AppSync Emulator.
Shmygol
  • 913
  • 7
  • 16
0

Although this post is 5 years old I think it is worth sharing 2023 solutions for AppSync local development for those searching for a contemporary approach:

ALFmachine
  • 639
  • 7
  • 12
-2

Here is a way to test your Appsync resolvers directly on AWS console. In the AppSync console, in the Schema tab, select a resolver and you will land into an "Edit resolver" page. Select the button "Select Test Context" to simulate a context received by your resolver. Then select "Run test".

hben
  • 35
  • 5
  • 2
    I was more interested in how to test is from a CI/CD perspective, where the integration/deployment server is running a series of tests prior to pushing the changes up through the environment. – CodeChimp Mar 29 '19 at 19:05