简体   繁体   中英

how to get data from dynamodb using rest api

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM