I'm trying to insert map data into a DynamoDB table using API Gateway. Here's my payload:
{
"TableName":"OrderDB",
"Item":{
"_id": {"S":"04FA887FP2S5R"},
"_rev": {"S":"9-12e098e2490e1b7c9782597226689403"},
"_merchantId":{"S":"AXN3EKXT0SJ61"},
"doc":{"M":{"something":"storedHere"} }
}
And my body mapping template in API Gateway:
{
"TableName": "$input.path('$.TableName')",
"Item": $input.json('$.Item')
}
Everything works as expected if I remove the doc item from the payload. With trying to post with the map I get the following error:
{
"__type": "com.amazon.coral.service#SerializationException",
"Message": "Unexpected value type in payload"
}
All of the examples that I see suggest using the DynamoDB document mapping object, but I don't think this is possible for me because I'm using API Gateway to connect directly to DynamoDB. Is it possible to insert a map this way?
Your map entry needs the same format as the rest of the items, so instead of "doc":{"M":{"something":"storedHere"} } it should be "doc":{"M":{"something":"S": "storedHere"} }
Related
I am following Hasura basic tutorial on creating a todo app https://hasura.io/learn/graphql/hasura-advanced/introduction/ and want to extend it and have few additional operations, but don't seem to be able. Setup is as in the tutorial - you have Tasks table with title, description, authorId, isComplete, isPublic column. Table permissions are setup as in the tutorial, so a user can only select their own or public tasks. They can also update only their own tasks. Operations I want to add:
Query only public tasks that are NOT theirs (additionally, inverse also - only theirs without public ones).
Mutate public tasks to complete that are not theirs (update isComplete without having permissions to other columns).
I could create views for the first case, but it seems too much of an effort for such a simple logic. I think both cases could simply be done with access to Request Header (x-hasura-user-id) like so:
query PublicTasksOnly {
tasks(where: {isPublic: {_eq: true}, authorId: {_neq: x-hasura-user-id}}) {
description
isComplete
title
}
}
But it seems that this is not possible. Any ideas/suggestions how to achieve this?
To my knowledge I do not think it is possible to reference http headers in your graphql queries. Have you tried passing the userId as a variable to the query? Something like the following:
query PublicTasksOnly($userId: String!) {
tasks(where: {isPublic: {_eq: true}, authorId: {_neq: $userId}}) {
description
isComplete
title
}
}
I am not quite sure what you want to achieve but if your problem gets solved by adding this header x-hasura-user-id then I can help you out.
You can copy the graphql endpoint from hasura console and hit simple http request to that endpoint with query and it's variables in request body. Sharing sample code here using http library axios:
import axios from 'axios';
axios({
method: 'post',
url: 'https://your-hasura-project-url.hasura.app/v1/graphql',
headers: { 'x-hasura-user-id': '< Your user id >' },
data: {
query: `query PublicTasksOnly {
tasks(where: {isPublic: {_eq: true}}) {
description
isComplete
title
}
}`,
variables: { userId: 'abc-xyz' }
}
})
This should solve your issue.
Im using the Firebase REST API to retrieve data with the GET method, this is the URL im executing:
const url = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/${dataBase}/documents/${collectionName}/${documentId}?&key=${apiKey}&pageSize=${pageSize}&pageToken=${nextPageToken}&orderBy=timestamp&startAt=${startTime}`;
But it return this error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"startAt\": Cannot bind query parameter. Field 'startAt' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"startAt\": Cannot bind query parameter. Field 'startAt' could not be found in request message."
}
]
}
]
}
}
If im omitting the paramemeter of startAt it works fine.
The format of startTime, id try it in all the following ways, and all return the same error:
Firebase return format: 2022-06-16T15:46:46.061Z
Unix Timestamp:1655394406
ISO 8601 date: 2022-06-16T15:46:46+00:00
What im doing wrong?
(For reference here is the official documentation where the startAt is explained)
You're calling the Firestore REST API, but are referencing the documentation for the REST API of the Realtime Database. While both products are part of Firebase, they are complete separate - and the API of one cannot be applied to the other.
For the documentation of the Firestore REST API, see https://firebase.google.com/docs/firestore/reference/rest
I'm attempting to use Python + requests to talk with MS Graph API (v1.0) in order to filter user objects by the onPremisesSamAccountName property but am receiving this error when sending the simple query:
endpoint = "https://graph.microsoft.com/v1.0/users"
query_parameters = {
'$filter': 'onPremisesSamAccountName eq \'somevalue\'',
'$select': 'id,displayName,mail,onPremisesSamAccountName'
}
user_graph_data = requests.get(
endpoint,
headers={'Authorization': 'Bearer ' + result['access_token']},
params=query_parameters
).json()
==============================
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'onPremisesSamAccountName' of resource 'User'.",
"innerError": {
"date": "...",
"request-id": "...",
"client-request-id": "..."
}
}
}
I am able to filter using this field while using Microsoft's Graph Explorer:
https://developer.microsoft.com/en-us/graph/graph-explorer and the corresponding Javascript call in the developer console shows a successful call and response based on the filter with onPremisesSamAccountName.
The MS Graph docs for v1.0 state that this is a supported field for filtering as well:
Returned only on $select. Supports $filter (eq, ne, NOT, ge, le, in,
startsWith).
I'm also able to successfully filter using other fields such as 'mail' (i.e. changing the $filter string from 'onPremisesSamAccountName eq \'somevalue\'' to 'mail eq \'somevalue\'' works just fine, so I don't believe this is a syntactical error)
I'm using AppSync with IAM auth with a DynamoDB resolver and Cognito. I'm trying to do the following.
{
"version": "2017-02-28",
"operation": "GetItem",
"key": {
"userId": $util.dynamodb.toDynamoDBJson($ctx.identity.username)
}
}
$ctx.identity.username is supposed to contain userId generated by Cognito and I'm trying to use it to fetch current user data.
Client side, I'm using AWS Amplify that tells me I'm currently logged:
this.amplifyService.authStateChange$.subscribe(authState => {
if (authState.state === 'signedIn') {
this.getUserLogged().toPromise();
this._isAuthenticated.next(true);
}
});
getUserLogged is the Apollo query that is supposed to returns user data.
What I've tried:
If I leave it like this, getUserLogged returns null.
If I replace in the resolver $util.dynamodb.toDynamoDBJson($ctx.identity.username) with a known userId like this $util.dynamodb.toDynamoDBJson("b1ad0902-2b70-4abd-9acf-e85b62d06fa8"): It works! I get this user data.
I tried to use the test tool in the resolver page but it only gives fake data so I can't rely on this.
Did I make a mistake? To me everything looks good but I guess I'm missing something?
Can I clearly see what $ctx.identity contains?
You'll want to use $ctx.identity.cognitoIdentityId to identify Cognito IAM users:
https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html#aws-appsync-resolver-context-reference-identity
You could see the contents of $ctx.identity by creating a Lambda resolver and logging the event or by creating a local resolver and returning the input that the mapping template receives:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-local-resolvers.html
My cognitoIdentityId looks like this: eu-west-1:27ca1e79-a238-4085-9099-9f1570cd5fcf
Could you please help to filter below JSON using eventId?
{
"-Kb2dYPV0yUXpD_1moc9": {
"eventId": 1,
"message": "sdfsdfsf",
"sentOn": 1485004202943
},
"-Kb2etFm1xHd8sSsESeK": {
"eventId": 1,
"message": "shdfhsf",
"sentOn": 1485004553847
},
"-Kb2etKON8nWVKS2R0sj": {
"eventId": 2,
"message": "shdfhsf",
"sentOn": 1485004553853
}
}
I'm using below URL,
https://xxxxxxxx.firebaseio.com/chats.json?orderBy="eventId"&equalTo=1
but getting constraint index field must be a json primitive error.
I want to retrieve chat objects with respect to particular event ID. I referred to the REST API, there, it was explained with simple JSON.
Please help me.
I've run into the same error before using the firebase REST api, and it was because I didn't have quotes around the value in the equalTo clause (e.g. equalTo="1")