learn icon indicating copy to clipboard operation
learn copied to clipboard

Using multiple backends from a single front end

Open mdoel opened this issue 5 years ago • 1 comments

The documentation at https://docs.amplify.aws/cli/teams/multi-frontend does a nice job of explaining how you can have multiple front-end apps share a common back-end. What's less clear is what is the best way to do the opposite - have a single Amplify app make use of multiple backends.

Imagine I was building a mobile app for a truck rental company to facilitate maintenance on their fleet. This company has one micro service for the trucks in the fleet and a separate micro service for the vendors capable of doing maintenance on those trucks. We want to build an app that allows someone to make use of both of those services. That same company probably has many other services (e.g. one for customers, another for sales, another for discounts, etc.) that we don't care about for this particular app.

What's the best way to use Amplify goodness (e.g. GraphQL APIs, DataStore) in this kind of a situation? The examples I see seem designed to help an app talk to a single service (e.g. ToDo app). Having some documentation for this would be great but I'd also be happy to just get pointed to some good resources.

mdoel avatar Oct 12 '20 20:10 mdoel

Hi Mike, yes I get your point about multiple backends to a single front end, but if you have been using Amplify for a while you would understand that the resources are limited to one aws-exports.js with each being a JSON object. Unless that is changed to an array list, hoping for multiple backends for the same frontend is a wish list. If needed, pretty rustic implementation would be having multiple API Gateway REST APIs which would do the job but for all the known reasons AppSync better than REST API any day.

However, if you are looking for multiple module based backends then you can build a micro-frontend that's possible over web apps where a container web app has multiple child app for each module and they can use the browser cookies for data communication but this is not possible on a native mobile app build on Android or iOS.

This is what helped me get into Micro-frontends, and resolve the problem of multiple backends for a single monolithic front-end.

zachjonesnoel avatar Aug 24 '21 15:08 zachjonesnoel

For anyone else who runs into this, using POST requests with sigv4 signatures may be a suitable workaround for calling alternate AppSync backends, as described in https://github.com/aws/aws-sdk-js-v3/issues/3530#issuecomment-1157207639 for nodejs

MaxDribinskyKodiak avatar Aug 10 '23 15:08 MaxDribinskyKodiak