Amplify-js: Confused with Amplify API Get

Created on 24 Aug 2018  路  2Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?: NO

What is the current behavior?: API Post is working. API Get is working too, but cannot get the result I want (will describe more below)

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than AWS Amplify.: Not Applicable

What is the expected behavior?: I would like to query using Get of API to get the results only I would like

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?:
"aws-amplify": "^1.0.6",
"aws-amplify-react-native": "^1.0.6",
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.2",
"npm": "5.6.0"

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

I am quite new to develop an app using React native and Amplify. I was confident to use Amplify Auth, but lost my peace of mind after trying to use DynamoDB through API (Lambda + API gateway) of Amplify.

There is a database table (say the name is TableA), and there are some items to try it out. The name of primary key is username and sort key is key2, and other attributes are given (like key3, key4, ...)

It was possible to add new data using API Post. However, I do not understand how API Get is working, and I am wondering if I use it on right way. Using Get, I could the list of whole items that has "test1" as username, but it is a bit hard for me how to query.

async componentDidMount() {
  await this.getUserId();
    const path = '/TableA';
    const query = {
    headers: {
     'Accept': 'application/json',
     'Content-Type': 'application/json',
   },
    queryStringParameters: {
     "TableName": "TableA",
     "Key": {
       "username": "test1",
       "key2": 1234567
     }
   }
 }
  try {
    const apiResponse = await API.get("TableACRUD", path, query);
  } catch (err) {
    console.log(err);
  }
}

I also tried like the below for queryStringParameters to get some special data, but is it correct? (FYI, whatever I typed for queryStringParameters, it returns the same thing, the list of whole data.

queryStringParameters: {
  username: "test1", // get item(s) that has "test1" for username attribute
  key2: 1234567 // get items(s) that has 1234567 for key2
}

Most helpful comment

@undefobj I am working on it right now.
After posting this, I searched other related posts here, and noticed that I need to look at lambda files and know how it works. (I used CLI to enable API gateway, lambda and configure background, and it is excellent!) In my case, to find an item using sort key, I had to use '/TableA/object/id' where id is the value of sort key. It was a bit confusing to me because I thought I could use queryStringParameter to do what I want, and I have never thought about the existence of object.
Based on the existing codes in the lambda file, I will enable some query what I need for my app.
I personally think it would be a great help if it is said on the documentation that I need to look at a lambda file, or a little bit of example how to query with sort key providing simple sample of dynamodb.

All 2 comments

@oneduckoo were you able to resolve your issue? Is there something that could have helped in the documentation or the API category functionality in this case?

@undefobj I am working on it right now.
After posting this, I searched other related posts here, and noticed that I need to look at lambda files and know how it works. (I used CLI to enable API gateway, lambda and configure background, and it is excellent!) In my case, to find an item using sort key, I had to use '/TableA/object/id' where id is the value of sort key. It was a bit confusing to me because I thought I could use queryStringParameter to do what I want, and I have never thought about the existence of object.
Based on the existing codes in the lambda file, I will enable some query what I need for my app.
I personally think it would be a great help if it is said on the documentation that I need to look at a lambda file, or a little bit of example how to query with sort key providing simple sample of dynamodb.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rayhaanq picture rayhaanq  路  3Comments

guanzo picture guanzo  路  3Comments

karlmosenbacher picture karlmosenbacher  路  3Comments

rygo6 picture rygo6  路  3Comments

callmekatootie picture callmekatootie  路  3Comments