16

How do I fetch Amazon DynamoDB data using a RESTful API?

Is there a way to get Amazon DynamoDB data using a REST url, and if so what are the required parameters to pass in the url?

We have considered the DynamoDB endpoint as the url and append it with the accesskey and the secretaccesskey, is anything more required to append to the url?

If any one has tried this with DynamoDB RESTful API, can you give me an example of how to get table data?

A sample url would also be good, something showing how to connect to DynamoDB through a RESTful API.

Ideally, a sample url with all the parameters required.

4 Answers 4

12

There is an AWS documentation including an example:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/MakingHTTPRequests.html

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately it seems like this isn't as easy as creating a curl or postman request. Generating the Authorization header isn't as easy as putting your AWS keys in the value.
2

You can use API gateway which points to a Lambda function to fetch the data from DynamoDB. End point of your API gateway URL will be your rest end point.

Comments

2

Here is a minimal JavaScript example of performing a GetItem operation on a DynamoDB table via the AWS API:

const DYNAMODB_ENDPOINT = 'https://dynamodb.us-east-1.amazonaws.com';
let aws = new AwsClient({ accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_SECRET_KEY });

async function dynamoDbOp(op, opBody) {
    let result = await aws.fetch(DYNAMODB_ENDPOINT, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-amz-json-1.0',
            'X-Amz-Target': 'DynamoDB_20120810.' + op
        },
        body: JSON.stringify(opBody)
    });

    return result.json();
}

let dbResponse = await dynamoDbOp('GetItem', {
    TableName: "someTableName",
    Key: {
        someTableKey: {
            S: "someKeyValue"
        }
    }
});

console.log(dbResponse.json());

Note that AwsClient is a class defined by aws4fetch which takes care of signing AWS requests for you. See the AWS GetItem API doc for more info.

Comments

1

That is not how Dynamo works, you will have to build your own RESTful API (i.e. use the AWS SDK for PHP) that hits Dynamo, reformats the data to however you want it then returns it. Quite easy to do :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.