Is it possible to use the amplify framework without using the cli?

怎甘沉沦 提交于 2020-08-05 04:17:31

问题


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.

  • https://aws.amazon.com/amplify/faqs/
  • https://docs.aws.amazon.com/amplify/?id=docs_gateway
  • https://aws-amplify.github.io/docs/

回答1:


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.




回答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.




回答3:


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.



来源:https://stackoverflow.com/questions/56455901/is-it-possible-to-use-the-amplify-framework-without-using-the-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!