aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

"Error: No credentials" on Amplify, works well on local #10486

Closed ekofi closed 2 years ago

ekofi commented 2 years ago

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: Windows 10 10.0.19044 CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics Memory: 5.13 GB / 15.37 GB Binaries: Node: 14.17.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.15 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.42) Internet Explorer: 11.0.19041.1566 npmPackages: @ampproject/toolbox-optimizer: undefined () @babel/core: undefined () @babel/runtime: 7.15.4 @edge-runtime/primitives: 1.1.0-beta.31 @hapi/accept: undefined () @napi-rs/triples: undefined () @next/react-dev-overlay: undefined () @segment/ajv-human-errors: undefined () @vercel/nft: undefined () acorn: undefined () amphtml-validator: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.8 => 10.4.8 aws-amplify: ^4.3.38 => 4.3.38 babel-packages: undefined () bootstrap: ^5.2.0 => 5.2.1 boring-avatars: ^1.7.0 => 1.7.0 browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () chalk: undefined () chart.js: ^3.9.1 => 3.9.1 chart.js-auto: undefined () chart.js-helpers: undefined () chartjs-adapter-moment: ^1.0.0 => 1.0.0 ci-info: undefined () cli-select: undefined () comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () cssnano-simple: undefined () debug: undefined () devalue: undefined () domain-browser: undefined () edge-runtime: undefined () emailjs: ^4.0.0 => 4.0.1 eslint: 8.17.0 => 8.17.0 eslint-config-next: 12.1.6 => 12.1.6 events: undefined () find-cache-dir: undefined () find-up: undefined () flowbite: ^1.5.2 => 1.5.3 flowbite-react: ^0.1.10 => 0.1.10 fresh: undefined () fs: 0.0.1-security => 0.0.1-security get-orientation: undefined () glob: undefined () gzip-size: undefined () html-to-image: ^1.9.0 => 1.10.8 http-proxy: undefined () https-browserify: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () json5: undefined () jsonwebtoken: undefined () jspdf: ^2.5.1 => 2.5.1 loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () moment: ^2.29.4 => 2.29.4 mysql: ^2.18.1 => 2.18.1 nanoid: undefined () native-url: undefined () neo-async: undefined () net: ^1.0.2 => 1.0.2 next: ^12.3.0 => 12.3.0 next-auth: ^4.13.0 => 4.13.0 node-fetch: undefined () node-html-parser: undefined () ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () postcss: ^8.4.16 => 8.4.16 (8.4.14) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () process: undefined () punycode: undefined () querystring-es3: undefined () raw-body: undefined () react: 18.1.0 => 18.1.0 react-chartjs-2: ^4.2.0 => 4.3.1 react-countdown: ^2.3.2 => 2.3.2 react-dom: 18.1.0 => 18.1.0 react-flags-select: ^2.2.3 => 2.2.3 react-flatpickr: ^3.10.13 => 3.10.13 react-globe.gl: ^2.22.3 => 2.22.3 react-is: 17.0.2 react-refresh: 0.12.0 react-server-dom-webpack: undefined () react-slick: ^0.29.0 => 0.29.0 react-toastify: ^9.0.8 => 9.0.8 react-transition-group: ^4.4.5 => 4.4.5 react-transition-group/CSSTransition: undefined () react-transition-group/ReplaceTransition: undefined () react-transition-group/SwitchTransition: undefined () react-transition-group/Transition: undefined () react-transition-group/TransitionGroup: undefined () react-transition-group/TransitionGroupContext: undefined () react-transition-group/config: undefined () regenerator-runtime: 0.13.4 remove-trailing-slash: ^0.1.1 => 0.1.1 sass-loader: undefined () schema-utils: undefined () semver: undefined () send: undefined () serverless-mysql: ^1.5.4 => 1.5.4 setimmediate: undefined () slick-carousel: ^1.8.1 => 1.8.1 source-map: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () tailwindcss: ^3.1.8 => 3.1.8 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tls: 0.0.1 => 0.0.1 tty-browserify: undefined () typewriter-effect: ^2.19.0 => 2.19.0 ua-parser-js: undefined () unistore: undefined () util: undefined () vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () npmGlobalPackages: @aws-amplify/cli: 10.2.1 @expo/ngrok: 4.1.0 corepack: 0.10.0 create-react-native-app: 3.8.0 expo-cli: 4.13.0 jest: 28.1.3 npx: 10.2.2 tiktok-scraper: 1.4.36 ```

Describe the bug

I created a GraphQL API. I can get the data with await DataStore.query(Model), there is no problem.

But, I can't create a new data with await API.graphql, using mutations.

Also, I CAN create a new data on my LOCAL but not on my Amplify hosting.

GraphQL API has API key auth + IAM as additional auth.

My CloudWatch console: Issue

Expected behavior

I need to create a data with await API.graphql , without a problem in my Amplify console and in "Content" section, I need to able to see my data.

Reproduction steps

  1. Create Next.js template, do amplify init
  2. Try to create data with mutations (search codegen first for get mutation files)
  3. It can work on your local, but try to do this in Amplify hosting.
  4. See your CloudWatch console.

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

chrisbonifacio commented 2 years ago

Hi @ekofi 👋 thanks for raising this issue.

Can you also share your graphQL schema for the model?

ekofi commented 2 years ago

Hi, thanks @chrisbonifacio. This is the schema:

type Level @model @auth(rules: [{allow: public}]) {
  id: ID!
  tap_uid: String
  value: Float
}

type Flow @model @auth(rules: [{allow: public}]) {
  id: ID!
  tap_uid: String
  value: Float
}
chrisbonifacio commented 2 years ago

@ekofi sorry, I should've also asked for the code snippets where you are calling DataStore.save or API.graphql?. I need to know if it is being called on the client or the server.

Also, can you confirm or share how you're configuring Amplify? I'm curious if you enabled ssr in the configuration.

ex.

Amplify.configure({...awsExports, ssr: true});

Another thing to try is attempt the same mutation in the AppSync console to rule out any platform specific causes.

You mentioned that you are using API Key + IAM, but your schema's auth rules only restrict the models to API Key (allow: public). To setup IAM auth on the model, you would have to adjust the models like so:

type Level @model @auth(rules: [{allow: public}, {allow: public, provider: iam}]) {
  id: ID!
  tap_uid: String
  value: Float
}

type Flow @model @auth(rules: [{allow: public}, {allow: public, provider: iam}]) {
  id: ID!
  tap_uid: String
  value: Float
}
chrisbonifacio commented 2 years ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!