Amplify-js: Is it possible to use two Amplify objects in the same project?

Created on 9 Jan 2019  路  10Comments  路  Source: aws-amplify/amplify-js

Is your feature request related to a problem? Please describe.
I would like to keep my Admin and Customer resources separate and I would like to use Amplify. My customer facing service would use a Customer

Describe the solution you'd like
const AmplifyAdmin = Amplify.configure(... admin config ... )
const AmplifyCustomer = Amplify.configure(... customer config ...)

Describe alternatives you've considered
Using Cognito groups (which Amplify supports -- at least for API) to obviate the need for a complete separation of resources. Perhaps packaging AmplifyAdmin and AmplifyCustomer as separate packages -- along with a wrapper for the services (AdminAPI, AdminStorage, CustomerAPI, CustomerStorage, etc.).

Additional context
Frankly, I don't think that Amplify should provide this service because it probably won't be needed frequently & could make things needlessly complicated for common. I am hoping that there might be a workaround to achieve this using the current framework, but I have not been able to come up with a solution.

Auth Cognito feature-request

All 10 comments

@ajhool I am not sure if I am understanding it correctly but people usually move the admin part into the server side and leave the customer part in the client side. So for services AdminAPI, AdminStorage, you should put it into the server side(or make it into a lambda function) and trigger those operations by API gateway.

@ajhool When you say 'admin', do you mean like a super-user of the app, such as someone who wouldn't actually log in to the AWS console but would rather use certain parts of the application perform administrative functions?

@haverchuck correct, I'm talking about a super-user of the app. Admin might not be the best term, but some of the amplify examples have an "admin" group. Admins would be able to query data created by the non-admins, but admins would also have additional tools that I would like to keep completely separate from the non-admins. Thus, there is a tiered "EverybodyAPI" which admins and non-admins can access with different privileges, but also an "AdminAPI" that only admins should be able to interact with. This can be done using a single Amplify object, but I would prefer to keep them separate if possible -- so, I'm curious if it is possible.

@ajhool - We have an RFC up in our CLI repo which I think addresses your use case (if not the actual implementation you describe). The functionality described in this RFC would still utilize a single Amplify object, but would allow for the configuration of more granular permissions. Please feel free to comment on this RFC. We would love to hear your feedback.

Closing this issue due to no further response. Please feel free to reopen if you still have this issue.

Sorry @powerful23 , I have temporarily moved away from the Amplify part of my code. The reason I did not reply to the @haverchuck RFC comment is because I initially didn't think that RFC is related to this issue in any way. I wanted to double-check that the RFC was unrelated before replying, but got sidetracked.

That RFC talks about performing Amplify Admin tasks related to AWS resources. That's a totally different topic than the one addressed in this issue. This issue is simply about whether multiple Amplify Singletons can be used simultaneously in one program. The "Admin" in the example I gave is just a user of the website and would have absolutely no access to AWS resources -- I could use the word "Owner" instead.

To clarify:

Let's say that I develop two separate web applications for a rideshare service. These are distinct applications and I create an Amplify project for each one. One react app is called "Drivers Web App @ www.drivers/com" and one app is called "Riders" @ www.rider/com . Those websites each uses its own Amplify project. Then, one day, I decide that it would be easier to just merge these two apps into one app. However, I already have two separate Amplify projects (one for the Drivers and one for the Riders). I'd rather not merge the two amplify projects and would instead like to simply do:

DriversAmplify = Amplify.configure('drivers.awsexports.json');
RidersAmplify = Amplify.configure('riders.awsexports.json');

AFAIK, that's not currently possible. It would be nice if it were possible.

@ajhool thanks for your clarification! As a conclusion, the feature is to make the Amplify library handle/manage multiple AWS resource stacks. I will mark this as feature request.

Correct, that's a good characterization of the issue, thanks!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Amplify's architecture acts as a "singleton" in the client, so running multiple Amplify instances in the browser isn't supported.

We recently did enable per-request encapsulation for SSR-support (via the withSSRContext utility), which shows it is possible:

https://docs.amplify.aws/lib/ssr/q/platform/js#withssrcontext

However, it's worth opening up further discussion (https://github.com/aws-amplify/amplify-js/discussions) to discuss the use-case in greater detail, given that truly solving the encapsulation problem on the client would be a large lift.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rygo6 picture rygo6  路  3Comments

rayhaanq picture rayhaanq  路  3Comments

romainquellec picture romainquellec  路  3Comments

josoroma picture josoroma  路  3Comments

callmekatootie picture callmekatootie  路  3Comments