Is there a way to test AppSync code locally and/or in CI/CD?
Asked Answered
C

3

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.

Cruciate answered 9/8, 2018 at 21:33 Comment(11)
Have you looked into this local resolver? You can use it to forward the result of the request mapping template to the response mapping templatePeggi
@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?Cruciate
You could set up a separate stack for dev/qa/prod. This way, your development stack and your prod stacks won't interfere.Peggi
@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.Cruciate
Maybe you can even use AWS CodePipeline to achieve CI/CDPeggi
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. :(Glazunov
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.Seedman
I just want to say, you're not "old school". 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.Perfidy
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 for an actual examplePitcher
@Cruciate 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 ?Phenacite
@Phenacite 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.Cruciate
Z
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.
Zetana answered 11/3, 2020 at 8:13 Comment(0)
S
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:

Siloa answered 21/8, 2023 at 15:6 Comment(0)
D
-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".

Dees answered 28/3, 2019 at 15:13 Comment(1)
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.Cruciate

© 2022 - 2024 — McMap. All rights reserved.