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.42k stars 2.12k forks source link

"No Cognito Identity pool provided for unauthenticated access" when using @aws-amplify/storage v5 #11029

Closed AndrzejSala closed 1 year ago

AndrzejSala commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Storage

Amplify Categories

storage

Environment information

``` # Put output below this line System: OS: macOS 11.4 CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz Memory: 370.62 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm Browsers: Firefox: 109.0.1 Safari: 14.1.1 Safari Technology Preview: 15.0 npmPackages: @actions/core: ^1.6.0 => 1.9.1 @actions/github: ^5.0.0 => 5.0.0 @apollo/client: ~3.7.0 => 3.7.0 @apollo/client/cache: undefined () @apollo/client/core: undefined () @apollo/client/errors: undefined () @apollo/client/link/batch: undefined () @apollo/client/link/batch-http: undefined () @apollo/client/link/context: undefined () @apollo/client/link/core: undefined () @apollo/client/link/error: undefined () @apollo/client/link/http: undefined () @apollo/client/link/persisted-queries: undefined () @apollo/client/link/retry: undefined () @apollo/client/link/schema: undefined () @apollo/client/link/subscriptions: undefined () @apollo/client/link/utils: undefined () @apollo/client/link/ws: undefined () @apollo/client/react: undefined () @apollo/client/react/components: undefined () @apollo/client/react/context: undefined () @apollo/client/react/hoc: undefined () @apollo/client/react/hooks: undefined () @apollo/client/react/parser: undefined () @apollo/client/react/ssr: undefined () @apollo/client/testing: undefined () @apollo/client/testing/core: undefined () @apollo/client/utilities: undefined () @apollo/client/utilities/globals: undefined () @aws-amplify/auth: ^4.5.6 => 4.5.6 @aws-amplify/core: ^4.5.6 => 4.5.6 (5.0.15) @aws-amplify/storage: ^5.0.0 => 5.1.5 @babel/core: 7.20.2 => 7.20.2 @babel/plugin-syntax-typescript: ^7.16.7 => 7.18.6 @babel/preset-env: 7.20.2 => 7.20.2 @babel/preset-react: 7.18.6 => 7.18.6 @babel/preset-typescript: 7.18.6 => 7.18.6 @babel/runtime: ^7.17.9 => 7.18.9 @graphql-codegen/add: ^3.2.0 => 3.2.0 @graphql-codegen/cli: ^2.8.0 => 2.8.0 @graphql-codegen/near-operation-file-preset: ^2.3.1 => 2.3.1 @graphql-codegen/schema-ast: ~2.5.0 => 2.5.0 @graphql-codegen/typescript: ^2.7.1 => 2.7.1 @graphql-codegen/typescript-apollo-client-helpers: ^2.2.1 => 2.2.1 @graphql-codegen/typescript-operations: ^2.5.1 => 2.5.1 @graphql-codegen/typescript-react-apollo: ^3.3.1 => 3.3.1 @nrwl/cli: 13.10.3 => 13.10.3 @nrwl/eslint-plugin-nx: 13.10.3 => 13.10.3 @nrwl/jest: 13.10.3 => 13.10.3 @nrwl/linter: 13.10.3 => 13.10.3 @nrwl/react: 13.10.3 => 13.10.3 @nrwl/web: 13.10.3 => 13.10.3 @nrwl/workspace: 13.10.3 => 13.10.3 @sentry/cli: ^2.10.0 => 2.10.0 (1.74.6) @sentry/integrations: 7.25.0 => 7.25.0 @sentry/react: 7.25.0 => 7.25.0 @sentry/types: ^7.11.1 => 7.25.0 @sentry/webpack-plugin: ^1.20.0 => 1.20.0 @testing-library/dom: ^9.0.0 => 9.0.0 @testing-library/jest-dom: ^5.16.4 => 5.16.4 @testing-library/react: 14.0.0 => 14.0.0 @testing-library/user-event: ^14.2.0 => 14.2.0 @types/fabric: ^4.5.8 => 4.5.11 @types/is-hotkey: ~0.1.7 => 0.1.7 @types/jest: 27.5.2 => 27.5.2 @types/lodash.throttle: ^4.1.6 => 4.1.6 @types/node: ^16.0.0 => 16.11.29 (18.0.1) @types/papaparse: 5.3.5 => 5.3.5 @types/react: 18.0.25 => 18.0.25 @types/react-dates: ^21.8.1 => 21.8.3 @types/react-dom: 18.0.8 => 18.0.8 @types/react-router-dom: 5.3.3 => 5.3.3 @types/react-transition-group: ^4.4.4 => 4.4.4 @types/styled-components: ^5.1.25 => 5.1.25 @types/uuid: ^9.0.0 => 9.0.0 @types/webpack: 5.28.0 => 5.28.0 @typescript-eslint/eslint-plugin: 5.42.1 => 5.42.1 @typescript-eslint/parser: 5.42.1 => 5.42.1 @vercel/ncc: ~0.34.0 => 0.34.0 amazon-chime-sdk-component-library-react: ^3.3.0 => 3.3.0 amazon-chime-sdk-js: ^3.8.0 => 3.8.0 apollo-link-sentry: ^3.2.0 => 3.2.0 aws-appsync: ^4.1.6 => 4.1.6 aws-appsync-auth-link: ^3.0.4 => 3.0.7 (2.0.8) aws-appsync-subscription-link: ^3.1.0 => 3.1.0 (2.3.0) babel-jest: 29.3.1 => 29.3.1 (27.5.1) babel-loader: 9.1.0 => 9.1.0 (8.3.0) base-tsconfig: 1.0.0 base-tsconfig-brainly-node: 1.0.0 brainly-style-guide: 220.4.0 => 220.4.0 classnames: ^2.2.6 => 2.3.1 core-js: ^3.21.0 => 3.22.2 css-loader: 6.7.1 => 6.7.1 dayjs: ^1.10.7 => 1.10.8 (1.8.36) env-cmd: ^10.1.0 => 10.1.0 eslint: 8.27.0 => 8.27.0 eslint-config-airbnb: ^19.0.4 => 19.0.4 eslint-config-airbnb-typescript: ^17.0.0 => 17.0.0 eslint-config-brainly: 2.5.0 eslint-config-brainly-legacy: 1.1.0 eslint-config-brainly-react: 2.8.0 eslint-config-brainly-typescript: 1.0.0 eslint-config-brainly-typescript-node: 1.0.0 eslint-config-brainly-typescript-react: 1.0.0 eslint-config-prettier: 8.5.0 => 8.5.0 eslint-plugin-css-modules: ^2.11.0 => 2.11.0 eslint-plugin-deprecation: ^1.3.2 => 1.3.2 eslint-plugin-graphql: ^4.0.0 => 4.0.0 eslint-plugin-import: 2.26.0 => 2.26.0 eslint-plugin-jest: ^27.0.0 => 27.0.4 eslint-plugin-jsx-a11y: 6.6.1 => 6.6.1 eslint-plugin-prettier: ^4.0.0 => 4.0.0 eslint-plugin-react: 7.31.10 => 7.31.10 (7.28.0) eslint-plugin-react-hooks: 4.6.0 => 4.6.0 express: ^4.18.0 => 4.18.0 fabric: ^5.2.1 => 5.2.1 frontend-tools-configs: 18.0.0 graphql: ^16.5.0 => 16.5.0 graphql-tag: ^2.12.6 => 2.12.6 history: ^5.2.0 => 5.3.0 http-proxy-middleware: ^2.0.0 => 2.0.3 husky: ^8.0.0 => 8.0.1 is-hotkey: ~0.2.0 => 0.2.0 (0.1.8) jest: ^27.5.1 => 27.5.1 jest-canvas-mock: ^2.3.0 => 2.3.1 lint-staged: ~13.0.0 => 13.0.3 lodash.throttle: ^4.1.1 => 4.1.1 lottie-web: ^5.8.1 => 5.9.1 mathlive: ~0.69.11 => 0.69.11 moment: ^2.29.4 => 2.29.4 nx: 13.10.3 => 13.10.3 papaparse: 5.3.2 => 5.3.2 pm2: ^5.2.0 => 5.2.0 pm2-plus-custom-metrics: 1.0.0 prettier: 2.7.1 => 2.7.1 python-app: 1.0.0 ramda: ^0.28.0 => 0.28.0 react: 18.2.0 => 18.2.0 react-dates: ^21.8.0 => 21.8.0 react-dom: 18.2.0 => 18.2.0 react-intersection-observer: ^9.1.0 => 9.1.0 react-is: 18.2.0 => 18.2.0 (16.13.1, 17.0.2) react-router-dom: 6.4.3 => 6.4.3 react-transition-group: ^4.3.0 => 4.4.2 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.7 => 0.13.9 resize-observer-polyfill: ^1.5.1 => 1.5.1 sass: ^1.49.7 => 1.49.9 sass-lint-config-brainly: 1.0.1 sass-loader: 13.2.0 => 13.2.0 (12.6.0) simple-http-server: 1.0.0 slate: ^0.80.0 => 0.80.0 slate-history: ^0.66.0 => 0.66.0 slate-react: ^0.80.0 => 0.80.0 style-loader: 3.3.1 => 3.3.1 styled-components: ^5.3.5 => 5.3.5 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () styled-system: ^5.1.5 => 5.1.5 ts-jest: 27.1.5 => 27.1.5 ts-key-enum: ^2.0.9 => 2.0.11 ts-node: ^10.7.0 => 10.7.0 (9.1.1) tslib: ^2.0.0 => 2.4.0 (2.0.3, 1.14.1, 2.2.0, 1.9.3, 2.1.0, 2.3.1) tslint: 6.1.3 => 6.1.3 typescript: 4.8.4 => 4.8.4 uglify-js: ^3.16.0 => 3.16.0 utility-types: ^3.10.0 => 3.10.0 uuid: ^9.0.0 => 9.0.0 (8.3.2, 3.4.0) webpack-cli: ^5.0.0 => 5.0.1 npmGlobalPackages: npm: 6.14.11 ```

Describe the bug

After updating the @aws-amplify/storage from 4.4.25 to 5.1.5 am not able to upload files becuase of No Cognito Identity pool provided for unauthenticated access error. I have checked the amplify storage changelog / docs, and there are no mentions about config shape updates.

Expected behavior

I want to be able to upload files using the newest version of amplify/storage

Reproduction steps

  1. Install @aws-amplify/auth: ^4.5.6 => 4.5.6 @aws-amplify/core: ^4.5.6 => 4.5.6 (5.0.15) @aws-amplify/storage: ^5.0.0 => 5.1.5

Code Snippet

// initializeAmplify.ts
import {Amplify} from '@aws-amplify/core';
import {Storage} from '@aws-amplify/storage';

const awsExports = {
  aws_appsync_graphqlEndpoint: appsyncGraphqlEndpoint,
  aws_appsync_region: appsyncRegion,
  aws_appsync_authenticationType: OauthType.AMAZON_COGNITO_USER_POOLS,
  aws_cognito_identity_pool_id: cognitoIdentityPoolId,
  aws_cognito_region: cognitoRegion,
  aws_user_pools_id: userPoolsId,
  aws_user_pools_web_client_id: userPoolsWebClientId,
};

const storageConfig = {
  AWSS3: {
    bucket: s3Bucket,
    region: s3Region,
  },
};

const initializeAmplify = () => {
  Amplify.configure(awsExports);
  Storage.configure(storageConfig);
}

// useS3Upload.ts
import {Storage} from '@aws-amplify/storage';

Storage.put(key, file, {
  contentType: file.type || undefined,
});

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 1 year ago

Hi @AndrzejSala 👋 thanks for raising this issue. Can you try updating all of your amplify packages to the latest version?

Config issues like these usually happen because of incompatible versions between scoped packages, which cause more than one Amplify instance to initialize.

There is a troubleshooting page for this:

https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js/

AndrzejSala commented 1 year ago

@chrisbonifacio Thanks for your advice. Updating all amplify libs at once helped, and I don't get the No Cognito Identity pool provided for unauthenticated access error anymore.

scottmanny commented 1 year ago

Worked for me too when I was having the same issue but with the @aws-amplify/api library. Thanks @AndrzejSala and @chrisbonifacio