Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API and Storage modules not registered when calling Amplify.configure #3505

Closed
christiankaindl opened this issue Jun 20, 2019 · 6 comments
Closed
Labels
API Related to REST API issues Storage Related to Storage components/category to-be-reproduced Used in order for Amplify to reproduce said issue

Comments

@christiankaindl
Copy link

christiankaindl commented Jun 20, 2019

Describe the bug
When using Amplify, I am unable to use Storage and API methods, and get respective errors (errors are below).

I am importing Amplify core package (@aws-amplify/core) and call the configure method like the following (code that is actually used):

import Amplify from '@aws-amplify/core'

Amplify.configure({
  Auth: {
    region: REGION,
    userPoolId: USER_POOL,
    identityPoolId: IDENTITY_POOL,
    userPoolWebClientId: USER_POOL_CLIENT
  },
  API: {
    endpoints: [
      {
        region: REGION,
        name: 'main',
        endpoint: API_ENDPOINT
      }
    ]
  },
  Storage: {
    AWSS3: {
      region: REGION,
      bucket: S3_BUCKET
    }
  }
})

Expected behavior
The Storage and API modules should work as documented.

Desktop (please complete the following information):

  • OS: Fedora 30 (Linux)
  • Browser: Chrome 74

Package.json dependencies:

....
},
  "dependencies": {
    "@aws-amplify/api": "^1.0.36",
    "@aws-amplify/auth": "^1.2.25",
    "@aws-amplify/core": "^1.0.28",
    "@aws-amplify/storage": "^1.0.31",
    "@material-ui/core": "^3.9.3",
    "@reach/menu-button": "^0.1.18",
    "@reach/router": "^1.2.1",
    "@reach/tabs": "^0.1.6",
    "classcat": "^3.2.5",
    "draft-js": "^0.10.5",
    "prop-types": "^15.7.2",
    "query-string": "^6.7.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-helmet": "^5.2.1"
  },
...

Additional context
React app, bundler is Parcel.


Log output: (the lines with Logging ... are from my code and log the Amplify object)
Screenshot from 2019-06-20 17-06-33

After that when my app imports the API module (@aws-amplify/api), using the post method, I get an API not configured error.
When importing and calling Storage.put, the error becomes:

Uncaught (in promise) TypeError: No plugin found in Storage for the provider
Uncaught (in promise) TypeError: Cannot read property 'put' of undefined

I suspect the API and Storage modules aren't registered, because they still give null when logged (the "BEFORE" and "AFTER" logs in the screenshot above). I reinstalled the node_modules multiple times already to have a clean install.

@Magneticoz
Copy link

Magneticoz commented Jun 21, 2019

@christiankaindl, I just had the same problem.
I've solved it on the way that I've separated configuration in my main.ts file.

So, instead of:

import Amplify from '@aws-amplify/core'

Amplify.configure({
  Auth: {
    region: REGION,
    userPoolId: USER_POOL,
    identityPoolId: IDENTITY_POOL,
    userPoolWebClientId: USER_POOL_CLIENT
  },
  API: {
    endpoints: [
      {
        region: REGION,
        name: 'main',
        endpoint: API_ENDPOINT
      }
    ]
  },
  Storage: {
    AWSS3: {
      region: REGION,
      bucket: S3_BUCKET
    }
  }
})

I did following:

import Storage from '@aws-amplify/storage';
import API from '@aws-amplify/api';
import Auth from '@aws-amplify/auth';

Auth.configure({
  Auth: {
    region: REGION,
    userPoolId: USER_POOL,
    identityPoolId: IDENTITY_POOL,
    userPoolWebClientId: USER_POOL_CLIENT
  }
});

API.configure({
  endpoints: [
    {
        region: REGION,
        name: 'main',
        endpoint: API_ENDPOINT
    }
  ]
});

Storage.configure(
  {
    AWSS3: {
      region: REGION,
      bucket: S3_BUCKET
    }
  }
);

Not sure if this is the best way of resolving it, but it did help in my case.

@sammartinez sammartinez added Storage Related to Storage components/category API Related to REST API issues to-be-reproduced Used in order for Amplify to reproduce said issue labels Jun 21, 2019
@christiankaindl
Copy link
Author

Thanks for your help @Magneticoz , really appreachiate it.

If I take your approach, then all modules seem to get configured but I get a 403 with response message "Missing Authentication Token" when calling API.post() (the call never reaches the Lambda function). Amplify logs a TypeError: "this._storage is undefined" error.
Here's the log output for API.post:

Screenshot from 2019-06-23 12-21-41

Note: Auth.currentAuthenticatedUser() and Auth.currentCredentials() return valid credentials.


When calling Storage.put I get a No credentials error:

Screenshot from 2019-06-23 12-09-41

Also note the AWSS3Provider - No Auth module registered warning. What could be the reason for Auth to not register? And why does Auth.currentAuthenticatedUser() work then?

@Magneticoz
Copy link

Magneticoz commented Jun 24, 2019

@christiankaindl, can you share your code for it? Both the configuration setup and the import to the certain component?

Because I have the same setup ( on Angular ) and it's working ( Auth, API & Storage ).

@ssk690
Copy link

ssk690 commented Jun 25, 2019

@christiankaindl , I was having the same issue (on React). So tried deleting node_modules and did npm install and the problem was solved.

@christiankaindl
Copy link
Author

Thanks for the help everyone! I got it working, here is a short summary:

The Request failed with the status code 403 error was caused by a wrong path on the API call:

API.post('main', '/getPosts'); // wrong
API.post('main', 'getPosts'); // Correct

The Auth problem was fixed by updating all packages again and deleting + reinstalling node_modules. Also tested to use the Amplify.configure method (as I originally did) to configure the modules instead of doing them individually and it also works:

Amplify.configure({
  Auth: {
    region: REGION,
    userPoolId: USER_POOL,
    identityPoolId: IDENTITY_POOL,
    userPoolWebClientId: USER_POOL_CLIENT
  },
  API: {
    endpoints: [
      {
        region: REGION,
        name: 'main',
        endpoint: API_ENDPOINT
      }
    ]
  },
  Storage: {
    AWSS3: {
      region: REGION,
      bucket: S3_BUCKET
    }
  }
})

I updated the packages a week ago, and now again two days ago. Otherwise I have no idea what else fixed it ¯_(ツ)_/¯

Many thanks for your help @Magneticoz and @ssk690 <3

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Related to REST API issues Storage Related to Storage components/category to-be-reproduced Used in order for Amplify to reproduce said issue
Projects
None yet
Development

No branches or pull requests

4 participants