PDA

View Full Version : DynamoDB HTTP Post



ttbgwt
16 Mar 2012, 11:54 AM
I'm looking into using Amazons DynamoDB, and was wondering how I can make the following request using extjs?




POST / HTTP/1.1
Host: dynamodb.us-east-1.amazonaws.com
x-amz-date: Mon, 16 Jan 2012 17:50:52 GMT
x-amzn-authorization: AWS3 AWSAccessKeyId=TemporaryAccessKeyID,Algorithm=HmacSHA256,SignedHeaders=Host;x-amz-date;x-amz-target;x-amz-security-token,Signature=*Signature Value*=
Date: Mon, 31 Oct 2011 17:49:52 GMT
x-amz-target: DynamoDB_20111205.GetItem
x-amz-security-token: *Token Value*
Content-Type: application/x-amz-json-1.0
Content-Length: 135
Connection: Keep-Alive
User-Agent: aws-sdk-java/1.2.10 Windows_7/6.1 Java_HotSpot(TM)_64-Bit_Server_VM/20.2-b06


{"TableName":"my-table",
"Keys":
[{"HashKeyElement":{"S":"Bill & Ted's Excellent Adventure"},
"RangeKeyElement":{"S":1989}}]
}


http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/UsingJSON.html

mitchellsimoens
16 Mar 2012, 11:57 AM
The only way to do a cross origin POST request is using CORS but the server needs to be able to send the headers for it

ttbgwt
16 Mar 2012, 12:06 PM
What if my extjs application was running on amazons EC2 and made the post from there? If this would work, how would I do this post and the headers using extjs?

mitchellsimoens
16 Mar 2012, 12:11 PM
If it is the same origin then it will just work without CORS.

ttbgwt
16 Mar 2012, 12:27 PM
would the ajax call look something like this?



Ext.Ajax.request({
url: 'dynamodb.us-east-1.amazonaws.com',
method: 'POST',
success: someFn,
failure: otherFn,
headers: {
'x-amz-date': 'Mon, 16 Jan 2012 17:50:52 GMT',
'x-amzn-authorization': 'AWS3 AWSAccessKeyId=TemporaryAccessKeyID,Algorithm=HmacSHA256,SignedHeaders=Host;x-amz-date;x-amz-target;x-amz-security-token,Signature=*Signature Value*=',
'Date': 'Mon, 31 Oct 2011 17:49:52 GMT',
'x-amz-target': 'DynamoDB_20111205.GetItem',
'x-amz-security-token': '*Token Value*',
'Content-Type': 'application/x-amz-json-1.0',
'Content-Length': '135',
'Connection': 'Keep-Alive',
'User-Agent': 'aws-sdk-java/1.2.10 Windows_7/6.1 Java_HotSpot(TM)_64-Bit_Server_VM/20.2-b06',
},
params: {
'TableName':'my-table',
'Keys': [
{
'HashKeyElement':{
'S': 'Bill & Ted's Excellent Adventure'
},
'RangeKeyElement': {
'S': 1989
}
}
]
}
});

mitchellsimoens
16 Mar 2012, 12:30 PM
You shouldn't need to send all the headers.