Open saurabhunde opened 7 months ago
Amplify documentation really needs a revamp. A lot of things are either not documented or fail to work :(
@nadetastic Please assist us with this issue.
If it helps, I am mentioning below links of previously riased issues of same project by our team. https://github.com.mcas.ms/aws-amplify/amplify-cli/issues/13240 https://github.com.mcas.ms/aws-amplify/amplify-js/issues/13119
Hello, @saurabhunde 👋. It looks like you're missing the identityPoolId
in your scoped Auth config. See an example of what the shape should look like here (click on existing resources block switcher). Can you add that in and see if you still get the error?
@sumitsahoo, that's valid feedback and we would love to hear how we can make it better! Feel free to open up a docs issue here or let me know via a reply back if there's something specific you're looking for. I think we could make the scoped examples for configs a little easier to find (rather than buried inside that last option of the block switcher).
@cwomack I have added identityPoolId
in the scoped Auth config and now the error has changed.
Updated Auth config:
Amplify.configure({
Auth: {
mandatorySignIn: false,
Cognito: {
userPoolClientId: amplifyconfig.aws_user_pools_web_client_id,
userPoolId: amplifyconfig.aws_user_pools_id,
loginWith: {
oauth: {
domain: amplifyconfig.oauth.domain,
scopes: ['openid email aws.cognito.signin.user.admin'],
redirectSignIn: ['http://localhost:5173'],
redirectSignOut: ['http://localhost:5173'],
responseType: 'code',
},
},
identityPoolId: amplifyconfig.aws_cognito_identity_pool_id,
},
},
API: {
GraphQL: {
endpoint:
xyz.aws_appsync_graphqlEndpoint,
region: 'eu-west-1',
// Set the default auth mode to "userPool"
defaultAuthMode: 'userPool',
},
},
Storage: {
S3: {
bucket: "xyz-dev",
region: "eu-west-1",
},
}
});
Here is error message:
InvalidIdentityPoolConfigurationException: Invalid identity pool configuration. Check assigned IAM roles for this pool.
at parseJsonError (http://localhost:5173/node_modules/.vite/deps/chunk-IFRJ7B24.js?v=ca1ab44f:2871:17)
at async getCredentialsForIdentityDeserializer (http://localhost:5173/node_modules/.vite/deps/chunk-IFRJ7B24.js?v=ca1ab44f:4387:19)
at async CognitoAWSCredentialsAndIdentityIdProvider.credsForOIDCTokens (http://localhost:5173/node_modules/.vite/deps/chunk-S5WU6PHE.js?v=ca1ab44f:4865:26)
at async AuthClass.fetchAuthSession (http://localhost:5173/node_modules/.vite/deps/chunk-IFRJ7B24.js?v=ca1ab44f:1010:34)
at async resolveS3ConfigAndInput (http://localhost:5173/node_modules/.vite/deps/chunk-K4YCOUCR.js?v=ca1ab44f:641:39)
at async list (http://localhost:5173/node_modules/.vite/deps/chunk-K4YCOUCR.js?v=ca1ab44f:1984:51)
at async listAllBuckets (http://localhost:5173/src/components/PAVManagement/PAVForm.jsx:68:22)
Hi @cwomack , Thank you for your reponse on my issue. Could you please provide an exmaple IAM role and its policies that we can add to Cognito Identity Pool which allows CRUD operations on S3 for authenticated Cognito users? As menioned by @sumitsahoo, we are facing above error even after adding identity pool id in Amplify configuration
I'm also getting similar. If I configure my Auth as follows, then basically every API I have starts complaining - these are all different Amplify projects that import the Auth cateory. There had been no changes prior to today and we were working on something unrelated to work round another bug.
Auth: {
Cognito: {
identityPoolId: <imported>
userPoolId: <imported>
userPoolClientId: <imported>
}
},
When I remove identityPoolId
the site and it's APIs work ok, but it breaks the ability to upload/create presigned URLs.
When identityPoolId
is configured as shown, I get:
message: "Invalid identity pool configuration. Check assigned IAM roles for this pool."
__type: "InvalidIdentityPoolConfigurationException"
When I remove identityPoolId
I get the following messages when trying to upload files:
Profile.tsx:361 Error: NoIdentityId: Missing identity ID when accessing objects in protected or private access level.
at assertValidationError (http://localhost:8000/node_modules/.vite/deps/@aws-amplify_storage.js?v=8c320a89:485:11)
at resolveS3ConfigAndInput (http://localhost:8000/node_modules/.vite/deps/@aws-amplify_storage.js?v=8c320a89:660:3)
at async http://localhost:8000/node_modules/.vite/deps/@aws-amplify_storage.js?v=8c320a89:1498:76
at async http://localhost:8000/node_modules/.vite/deps/@aws-amplify_storage.js?v=8c320a89:529:22
at async customRequestFileUploader (http://localhost:8000/routes/Profile.tsx?t=1721830282460:291:28)
My upload configuration is as follows:
const uploadedFile = await uploadData({
path: ({identityId}) => `protected/${identityId}/profile.${fileExtension}`,
data: file,
options: {
onProgress // Optional progress callback.
}
}).result;
Finally, when I call:
const { username, userId, signInDetails } = await getCurrentUser()
const authSession = await fetchAuthSession()
signInDetails
are empty, as is the identityId
in the response from fetchAuthSession()
I was having similar issues switching between public (apiKey) and Cognito user pool users. Would get errors like NoCredentials
or NoValidAuthTokens
when I would sign out and try to switch to apiKey or sign in and switch Amplify config to userPool. What worked was not messing around w re-configuring Amplify and just switching auth modes when calling generateClient() for API calls.
import amplifyconfig from '../amplifyconfiguration.json'
import { generateClient } from 'aws-amplify/api'
...
Amplify.configure(amplifyconfig,{})
...
getClient() {
return generateClient({ authMode: store.getState().appStateInRedux.signedIn ? 'userPool' : 'apiKey' })
}
...
//if userSub, then we have a userPool user, call s3 api
fetchAuthSession().then((session) => {
userSession = session
if (userSession.userSub) {
uploadFilePath = 'protected/' + userSession.identityId + '/' + fileName
}
const uploadedFile = await uploadData({
path: uploadFilePath,
data: file,
}).result
}
...
//other places where I call the AppSync API
getClient().graphql(...)
I could not find this documented anywhere, the authMode param in generateClient, however it is there if you check the types for CommonPublicClientOptions
. Hopefully this helps someone. This is a react native project and aws pkg details below:
"aws-amplify": "6.3.6"
I'm also running into this, aws-amplify 6.6.0. Auth and storage configured manually. I hadn't had an identity pool configured, but finally figured out that that was why the auth session had no identityId
, leading to storage breakage. As soon as I added an identity pool, got "Invalid identity pool configuration. Check assigned IAM roles for this pool."
.
@sumitsahoo How are you creating your identityPool? Are you doing it manually or via CLI? If manually, it appears to me that there might be a misconfiguration issue between IAM and the identityPool.
@sumitsahoo How are you creating your identityPool? Are you doing it manually or via CLI? If manually, it appears to me that there might be a misconfiguration issue between IAM and the identityPool.
We created it manually and then imported it from Amplify console.
@saurabhunde and others following this issue, I'll work on reproducing this locally and following up with any additional questions. With the amount of people experiencing this, it sounds like there's either a bug or (at minimum) a gap in our documentation.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Storage
Amplify Version
v6
Amplify Categories
auth, storage
Backend
Amplify CLI
Environment information
Describe the bug
I am trying to perform List, Upload file actions in my amplify react application. But I am getting below error while performing file upload and list files operations.
Error : NoCredentials: Credentials should not be empty.
Note- We are using federated usrs from Azure AD and have configured Azure AD ipd using SAML. All of the users will logging through this idp only. And we need to provide S3 file access to logged in users only.
I followed below steps to add and configure storage using Amplify CLI. Please refer below section
Expected behavior
Reproduction steps
amplify add storage
Answered questions like below
Content (Images, audio, video, etc.)
Yes
Default configuration
No, I am done.
testS3
testS3bucket
Auth users
create/update, read, delete
No
Configured- Amplify.configure({ .... //added S3 config Storage: { S3: { bucket: "testS3bucket", region: "us-east-1", } } })
Refer File upload and List files code from below code snippets
Code Snippet
Log output
Console Error while listing files
Console error while upload
aws-exports.js
No response
Manual configuration
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