18

The amplify FAQ says specifically you can. But the github links now just redirect you to the main amplify page and the instructions only talk about using the cli.

Q: Can I use the Amplify Framework libraries even if I do not use the CLI? Yes. The libraries can be used to access backend resources that were created without the Amplify CLI.

Jeremy
  • 625
  • 8
  • 12
  • I guess I had the same issue. Amplify CLI provisions lots of things in AWS that we did not asked for in the first place. Also, we do not know what they are for and we can not touch them otherwise everything brakes apart. CLIs was supposed to help the dev process, not to try to do our job with lots of obscure work behind the scenes. Amplify CLI is just madness. The framework is good though. – danb4r Dec 11 '22 at 12:46

5 Answers5

28

I have learned that you are able to use the amplify libraries without the Amplify CLI.

To do this you simply install the amplify library as normal.

In react web:

npm install --save aws-amplify
npm install --save aws-amplify-react

After that you need to manually configure any features you're going to use with Amplify.configure();. You can find the manual configuration in the Amplify documentation for each library you plan to use.

Here is an example using Cognito:

https://aws-amplify.github.io/docs/js/authentication#manual-setup

Amplify.configure({
    "aws_project_region": process.env.REACT_APP_REGION,
    "aws_cognito_identity_pool_id": process.env.REACT_APP_IDENTITY_POOL_ID,
    "aws_cognito_region": process.env.REACT_APP_REGION,
    "aws_user_pools_id": process.env.REACT_APP_USER_POOL_ID,
    "aws_user_pools_web_client_id": process.env.REACT_APP_CLIENT_ID,
    "oauth": {},
    Auth: {
        // REQUIRED - Amazon Cognito Identity Pool ID
        identityPoolId: process.env.REACT_APP_IDENTITY_POOL_ID,
        // REQUIRED - Amazon Cognito Region
        region: process.env.REACT_APP_REGION, 
        // OPTIONAL - Amazon Cognito User Pool ID
        userPoolId: process.env.REACT_APP_USER_POOL_ID, 
        // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
        userPoolWebClientId: process.env.REACT_APP_CLIENT_ID,
    }
});

You do not have to use the amplify push for deployments. You can manually deploy and configure any features you're working with.

I find this approach gives you full control over using the Amplify library without the overhead of the CLI and deployment process.

Jeremy
  • 625
  • 8
  • 12
  • 1
    I think the manual *Cognito* setup link is broken. – Mohammed Noureldin Apr 13 '21 at 00:49
  • I tend to agree with Mohammed, I think the link is out dated. AWS tends to update docs pretty often so not much of a surprise. I landed here because I was looking for a away to manually configure cogntio, [this](https://docs.amplify.aws/lib/auth/start/q/platform/js#re-use-existing-authentication-resource) link seemed useful. – John Hoffmeyer May 05 '21 at 01:53
  • You don't need to import the whole of Amplify. https://dabit3.medium.com/modular-imports-with-aws-amplify-daeb387b6985 – Sigex Nov 03 '21 at 21:43
  • This configure block duplicates most of the options unnecessarily. – Nick K9 Feb 16 '22 at 12:07
  • For all searching the current doc link: https://docs.amplify.aws/lib/auth/start/q/platform/js/#re-use-existing-authentication-resource – Simon Schnell Mar 27 '22 at 02:47
6

Yes, this is possible. As pointed out by Mohammed, this is covered in the documentation, although they definitely aren't in a hurry to inform you that this option is available. Anyway, the setup for a React app is:

npm install aws-amplify @aws-amplify/ui-react

And then all you have to do is:

import Amplify from '@aws-amplify/core';
import { withAuthenticator } from '@aws-amplify/ui-react';

Amplify.configure({
  Auth: {
    region: 'XX-XXXX-X',
    userPoolId: 'XX-XXXX-X_abcd1234',
    userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
    mandatorySignIn: true,
  }
});

export default withAuthenticator(function Home() {
  return (<h1>Protected Content</h1>)
})

PLEASE NOTE: as of February 2022, the Amplify UI components for auth recently changed their API substantially. You'll find lots of old posts and documentation about AmplifyAuthenticator and its child components, like this page for example. If you try to use these examples with the current version of Amplify UI, it will fail without explaining why! You need to be using the Authenticator component. Instead, use the examples in the Amplify UI docs.

Nick K9
  • 3,885
  • 1
  • 29
  • 62
  • so it is Authenticator instead of withAuthenticator now? Maybe you can update the config code too? – Jun Apr 16 '23 at 00:31
  • 1
    You can use either the `Authenticator` component directly or the `withAuthenticator` higher-order component as I have shown above. More info [here](https://ui.docs.amplify.aws/react/connected-components/authenticator#step-3-add-the-authenticator). What needs to be updated about the configuration code? – Nick K9 Apr 16 '23 at 12:20
  • Thanks, I thought withAuthenticator were replaced by Authenticator – Jun Apr 18 '23 at 01:00
2

You can, if you know what you are doing. The devil is in the details. The docs say:

Can I use the Amplify Framework libraries even if I do not use the CLI? Yes.

Notice how it explicitly says framework libraries. This means you can't generate resources manually. (Technically, you could write the templates yourself, but AFAIK you would still need the CLI's amplify push command to affect the cloud.) But you can use the framework components.

This means, you can for example manually configure AWS Amplify to use a custom GraphQL endpoint and then use the helpers, components and methods exposed by the framework (e.g. graphqlOperation) to make your requests.

halfer
  • 19,824
  • 17
  • 99
  • 186
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
  • Thank you for verifying. I did find out you do not need to use amplify push. – Jeremy Oct 17 '19 at 20:10
  • If you are not using the Amplify CLI then there is no ability to push or pull. You would be making the AWS resources yourself, I highly recommend you do that using Terraform, specifically with modules not individual resources as its easier to setup/ – Sigex Nov 03 '21 at 21:45
1

I'm using the react amplify libraries with Auth, AppSync and Storage that were manually setup, so it is doable.

For setting up S3 you can follow the guide here. For AppSync setup I'm using this plugin.

Erez
  • 1,690
  • 8
  • 9
1

Well this should be pretty much no problem. It is mentioned that you are able to use Amplify library without the CLI in the official docs:

If you are not using the Amplify CLI or need to override these settings, this documentation shows the available configuration properties for each category.

So from that you see that this is ok.

In the following link you may find the configuration (that normally gets generated) for the different services:

https://docs.amplify.aws/lib/client-configuration/configuring-amplify-categories/q/platform/js#general-configuration

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99