aws-samples / api-gateway-secure-pet-store

Amazon API Gateway sample using Amazon Cognito credentials through AWS Lambda
Apache License 2.0
308 stars 113 forks source link

PetTest iOS App: After logging in, screen hangs showing spinning "Loading pet list". #8

Closed ljbrown238 closed 8 years ago

ljbrown238 commented 8 years ago

Followed instructions on Roles, Tables, Lambda, API Gateway upload, etc. User has been registered and is in Cognito. User data appears in DynamoDB /users table. The user has logged in successfully and gets credentials (show by console). DynamoDB pets table does have data in it. But the Master/Detail screen simply spins "Loading pet list". This happens on simulator and physical hardware. Any ideas of what may be happening?

sapessi commented 8 years ago

Do you see the request being accepted by API Gateway & Lambda? ie does it appear in the API Gateway dashboard & Lambda logs?

ljbrown238 commented 8 years ago

Examining the logs/metrics in CloudWatch, API Gateway & Lambda are both called for: registering, as well as separately logging in from the iOS PetTest application. However, once logged in, I am observing the "Loading pet list" spinning. (again, even though there is data in the database). It appears that my settings in the PetTest/ClientSDK/PETLambdaMicroserviceClient.m fle of the PetTest App are correct for the deployed API Gateway API, otherwise it would not hit /login and /users. The part that I wonder about is the authenticated paths. I have no way of "manually" exercising /pets from the API Gateway Console since I can't pass in the temporary keys, token, etc. in the Console. (I hope there is a feature added for that soon! - or if there is a better way to debug the AUTH paths, please let me know.)

ljbrown238 commented 8 years ago

After completely rebuilding both the lambda and API functions, and placing both of them in the same region (just to be sure), I'm still getting the same result with the iPad. It can log in and I see the log in CloudTrail for the API Gateway and Lambda functions, but after logging in, it just spins. Clicking on the plus button anyway to attempt to add a pet results in the red bar sliding down from the top of the app - and there is no log in CloudTrail for the API Gateway ever having been called. At the least it seems that the App should be indicating an error if it is unable to get a response for sending a request to list pets, but it just spins. Thank you for looking into this! This app is a great model, I just need to close the loop in getting the iOS app to work to demo/sell the idea of using API Gateway/Lambda/Cognito/DynamoDB.

sapessi commented 8 years ago

It could be something related to the Cognito role. Can you check the access and trust policies for the authenticated role in your Cognito identity pool? Erase the resource ids (ARN) and paste them here? Also don't post the role ARN, I just want to check the policies

ljbrown238 commented 8 years ago

That was exactly the issue. For some ignorant reason, I had followed the directions, but modified a closely named set of Auth/Unauth Cognito roles, instead of the ones that were actually attached to the identity pool in use. It now works! Thank you so much for helping me out!!!

As an aside, it would be awesome if there was also a sample website "application" that accomplished the same thing to demonstrate using HTML/JavaScript. Also nice would be having a set of other languages in addition to Java 8 for Lambda functions to accomplish the same thing as this (Node.js, Python, etc.) Excellent demo app! Thanks again. :-)

sapessi commented 8 years ago

Glad this is fixed and thanks for the feedback, we'll look into adding more clients / server-side languages.