Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AWS SDK hell... help!

Discussion in 'Scripting' started by ArmanOhanian, Sep 5, 2016.

  1. ArmanOhanian

    ArmanOhanian

    Joined:
    May 2, 2015
    Posts:
    6
    Hi guys,

    (if you think this question belongs on AWS forum, please let me know)

    I am not trying to do anything fancy, just a simple query on an existing table. All the permissions are open. I can make queries against this table in Python, but in Unity... the debugger seems to skip over all client.*Async calls.

    Now, the cognito portion is fine as it sets the datasets.
    With Dynamodb, it works ONCE right after I create a new cognito user pool. The second time around, the debugger steps right over the client.QueryAsync(...) call, as if it's not even there.


    I am using unity 5.3.3f1 and AWS aws-sdk-unity_3.1.95.0.

    So much said, here is the code:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System;
    5. using Amazon;
    6. using Amazon.DynamoDBv2;
    7. using Amazon.DynamoDBv2.DataModel;
    8. using Amazon.DynamoDBv2.DocumentModel;
    9.  
    10. using System.Collections.Generic;
    11. using Amazon.CognitoIdentity;
    12. using Amazon.DynamoDBv2.Model;
    13. using Amazon.Util;
    14. using Amazon.Runtime;
    15.  
    16. using System.Text;
    17.  
    18. public class QuestionManager : MonoBehaviour
    19. {
    20.     public int limit = 5;
    21.     public string content;
    22.     public GameObject Cognito;
    23.     private IAmazonDynamoDB client;
    24.  
    25.     private DynamoDBContext Context;
    26.     private AWSCognitoSync cognitoSync;
    27.     private CognitoAWSCredentials cred;
    28.     public string resultText;
    29.  
    30.     public void qInit()
    31.     {
    32.  
    33.         cred = cognitoSync.Credentials;
    34.         client = new AmazonDynamoDBClient(cred, RegionEndpoint.USEast1);
    35.         Context = new DynamoDBContext(client);
    36.         GetQuestions("Music");
    37.     }
    38.  
    39.  
    40.     public void GetQuestions(string category)
    41.     {
    42.         QueryRequest request = new QueryRequest();
    43.         request.TableName = "Questions3";
    44.         request.Limit = 10;
    45.         request.ReturnConsumedCapacity = "TOTAL";
    46.  
    47.        
    48.         request.KeyConditionExpression = "category = :v_id";
    49.         request.ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
    50.         {
    51.           ":v_Id", new AttributeValue {
    52.             S = category
    53.           }
    54.         }
    55.         };
    56.  
    57.         client.QueryAsync(request, (result) =>
    58.         {
    59.  
    60.             if (result.Exception != null)
    61.             {
    62.                 Debug.Log("Failed to Query");
    63.             }
    64.  
    65.             Debug.Log("Entered QuerySync");
    66.             resultText = string.Format("No. of reads used (by query in FindRepliesForAThreadSpecifyLimit) {0}\n",
    67.                                              result.Response.ConsumedCapacity.CapacityUnits);
    68.             Debug.Log("resultText ---->" + resultText);
    69.  
    70.  
    71.             foreach (var item in result.Response.Items)
    72.             {
    73.                 Debug.Log(item);
    74.             }
    75.         });
    76.    }
    77. }
    78.  
    79.  
    80.  
    Any thoughts would be appreciated....
     
  2. ArmanOhanian

    ArmanOhanian

    Joined:
    May 2, 2015
    Posts:
    6
    ok, found the issue.

    Posting for the next guy who goes nuts over a non-issue...

    The problem was... that the GameObject the Cognito was attached to was being destroyed as I loaded the next level...

    Solution: Added a script to the Cognito GameObject to preserve it from one scene to another.

    Here is the code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class DontDestroyOnLoad : MonoBehaviour {
    4.  
    5.     public void Awake()
    6.     {
    7.         MonoBehaviour.DontDestroyOnLoad(this);
    8.     }
    9. }
     
    Kurt-Dekker likes this.