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

How on earth do I get aws_cognito_identity_pool_id to auto-populate in aws-exports.js? #7184

Closed
ghost opened this issue Apr 26, 2021 · 8 comments
Labels
pending-response Issue is pending response from the issue author question General question

Comments

@ghost
Copy link

ghost commented Apr 26, 2021

Amplify CLI Version

4.49.0

What AWS Services are you utilizing?
Amplify, Dynamo, S3

Provide additional details e.g. code snippets

Calling Storage.put in my app is failing because aws_cognito_identity_pool_id isn't defined in my aws-exports.js file. I can manually edit my local aws-exports.js to define the correct aws_cognito_identity_pool_id, and calling s3 works fine after that (locally), but editing an auto-generated file like aws-exports.js is obviously not ideal. I don't want to have to check it in.

I tried importing an existing auth into my development environment, but doing that forces me to "remove" the existing auth, which deletes all the templates that define how to create my app's auth scheme. And it looks like I will have to manually reconfigure the auth for my other environments if I go that route, too.

Is there a config file or template someplace where I can simply add the correct identity pool id that I want the app to use with my existing user pool.. without blowing away the definition of my existing user pool? So it'll automagically show up in aws-exports.js when it gets auto-generated? That would be ideal.

Thanks.

@ghost ghost added the question General question label Apr 26, 2021
@ghost ghost changed the title How on earth do I get aws_cognito_identity_pool_id to auto-populate in aws-amplify.js? How on earth do I get aws_cognito_identity_pool_id to auto-populate in aws-exports? Apr 26, 2021
@ghost ghost changed the title How on earth do I get aws_cognito_identity_pool_id to auto-populate in aws-exports? How on earth do I get aws_cognito_identity_pool_id to auto-populate in aws-exports.js? Apr 26, 2021
@edwardfoyle
Copy link
Contributor

Hi @Trevor-mc2 the aws-exports.js file should be generated anytime you run amplify init, amplify push, amplify pull or amplify env checkout. Have you run one of those commands since adding auth to your project?

@edwardfoyle edwardfoyle added the pending-response Issue is pending response from the issue author label Apr 27, 2021
@ghost
Copy link
Author

ghost commented Apr 27, 2021

Oh yes, for sure. I have definitely regenerated aws-exports.js multiple times since adding auth. I've run all of those commands at one point or another. I even tried deleting the file to be sure it was being recreated...

But the aws_cognito_identity_pool_id associated with my user pool still isn't being automagically added to aws-exports.js... which if why I'm wondering if there's something I can do to get it to show up in that file.

Thanks.

@ghost
Copy link
Author

ghost commented Apr 30, 2021

Okay, so.. what part of the Amplify setup process links the id pool with the user pool? I had this working once, but the Amplify defaults for username were case-sensitive, so I had to delete that auth setup and create a new one. And now I don't get an id pool id injected into my aws-exports.js file.

Is there a way to add that user-pool-to-identity-pool association in an Amplify config file someplace? Ideally without having to delete my entire user pool and re-create it from scratch (again) with the Amplify CLI?

Thanks. Appreciate you getting back to me, @edwardfoyle

@ghost
Copy link
Author

ghost commented May 2, 2021

So.. I was exploring the options in amplify auth update and came across this:

Do you want to enable any of the following capabilities?  
Do you want to use an OAuth flow? 
I want to learn more. 

When you create a user pool in Amazon Cognito and configure a domain for it, Amazon Cognito automatically provisions a hosted web UI to let you add sign-up and sign-in pages to your app. Selecting "No" will remove any existing OAuth configuration.
Do you want to use an OAuth flow? No
Warning! Your existing IdentityPool: undefined will be deleted upon the next “amplify push”!

That "undefined" IdentityPool value explains why my app no longer has an identity pool defined in aws-exports.js. So apparently I need to choose to add an OAuth flow if I want Amplify to automatically configure an identity pool...

...
I did some research, and found a bug where someone else complained about the creation of an identity pool when adding an OAuth flow:
"I set up auth with Cloud API only, an Identity Pool was not created. I then added redirect URIs to OAuth and suddenly it deployed an Identity Pool."
#4657

...
So I set up an OAuth login flow in my existing app, and did an amplify push, and despite all that, aws_cognito_identity_pool_id is still not being added to my aws-exports.js file. Running aws cognito-identity list-identity-pools --max-results 60 in the CLI shows no new identity pool was added. Sad times in Amplify-land. Any ideas?

...
The saga continues.. I set up a fresh Amplify project from scratch. Added Auth. With OAuth integration. That project also generated an aws-exports.js file without an entry for aws_cognito_identity_pool_id. Unless I'm missing something.

I'm running the very latest version of Amplify CLI: 4.50.0.

...
Last year, the first time I set up a new Amplify project, the time it worked, the setup process generated a file called amplify/backend/awscloudformation/nested-cloudformation-stack.yml, and that defined identityPoolName as one of the parameters that defined my auth stack. I don't see anything like that in the template that defines my new auth stack.

...
The plot thickens... I tried adding storage to the brand new Amplify project, and got this error, which I also cannot find a solution to:
Current auth configuration is: userPoolOnly, but identityPoolAndUserPool was required.

So... How on earth do I get the auth config set correctly? Nothing in the current myAuth-cloudformation-template.yml file even mentions an identity pool id, though I do see the entry for authSelections - but I don't imagine anything good will happen if I manually change it from "userPoolOnly" to "identityPoolAndUserPool" without defining the identity pool someplace.

@ghost
Copy link
Author

ghost commented May 3, 2021

Oh interesting. When I created a new Amplify project from scratch, the yml template for the Auth did contain a section that defined an identity pool:

  # BEGIN IDENTITY POOL RESOURCES
  

  IdentityPool:
  # Always created
    Type: AWS::Cognito::IdentityPool
    Properties:
      IdentityPoolName: !If [ShouldNotCreateEnvResources, 'test_identitypool_abcd123', !Join ['',['test_identitypool_abcd123', '__', !Ref env]]]

"Always created"... Hah. Haha.

Now, looking at my current system's Auth template, I see no such thing. No mention of identity pools. That template looks real old, though... it looks nothing like the one that Amplify just generated for my new project. My original template file starts with AWSTemplateFormatVersion: 2010-09-09 so... maybe it's just way too far out of date? Is it possible to upgrade the old system's auth template format without borking everything? Or do I need to remove the old Auth, define a new Auth in my old system, and make everyone set up a new login? (that seems excessive to me)

edit: the new template also says AWSTemplateFormatVersion: 2010-09-09 at the top, so I guess that doesn't mean anything.

@edwardfoyle
Copy link
Contributor

@Trevor-mc2 when you set up auth, did you select Default configuration in response to this question:

 Do you want to use the default authentication and security configuration? (Use arrow keys)
❯ Default configuration
  Default configuration with Social Provider (Federation)
  Manual configuration

You can also update this by running amplify update auth => select Walkthrough all the auth configuration => ensure User Sign-Up, Sign-In, connected with AWS IAM controls is selected => step through remaining config without changing anything.

It sounds like the auth resource is configured with just a User Pool and doing the above should add an identity pool as well

@ghost
Copy link
Author

ghost commented May 4, 2021

O. M. G. I had never tried the default Auth configuration. 🤦‍♂️

Nor had I tried enabling AWS IAM controls for my user pool. A million thanks. That's what ended up working for me.

Thanks so much for the assist! I'm all good now.

@ghost ghost closed this as completed May 4, 2021
@github-actions
Copy link

github-actions bot commented Jun 3, 2021

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 for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending-response Issue is pending response from the issue author question General question
Projects
None yet
Development

No branches or pull requests

1 participant