Connect to dynamodb C8
Node/Javascript
Install AWS SDK
npm install aws-sdk --save
Import package
// import entire SDK
import AWS from "aws-sdk";
// import AWS object without services
import AWS from "aws-sdk/global";
// import individual service
import DynamoDB from "aws-sdk/clients/dynamodb";Initialize Dynamodb with Macrometa Dynamo
import AWS from "aws-sdk";
const dcName = "test.macrometa.io";
const host = "https://api-" + dcName;
const apiKey = "xxxxxxxxxxxxxxxxxxxxxx";
/*
If you have a JWT token
const JWT = "xxxxxxxxxxxxxxxxxxxxxx";
*/
const service = "dynamodb";
const region = "us-east-1";
const endpoint = host + "/_api/dynamo";
// secretAccessKey is a required parameter for aws-sdk we recommend you to pass "c8"
const secretAccessKey = "c8";
const accessKeyId = "apikey " + apiKey;
/*
If you are using JWT token use the below instead
const accessKeyId = "bearer " + JWT;
*/
AWS.config.update({
region,
endpoint,
accessKeyId,
secretAccessKey,
});
var dynamodb = new AWS.DynamoDB();
...
...
Browser
If you want to sign and send AWS requests in a modern browser, or an environment like Cloudflare Workers, for dynamodb instance checkout mmdynamo, everything else check out aws4fetch. Consider reading API References for AWS service you are using(eg: dynamodb)
Add AWS SDK
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.7.16.min.js"></script>
Initialize Dynamodb with Macrometa Dynamo
<script type="text/javascript">
const dcName = "test.macrometa.io";
const host = "https://api-" + dcName;
const apiKey = "xxxxxxxxxxxxxxxxxxxxxx";
/*
If you have a JWT token
const JWT = "xxxxxxxxxxxxxxxxxxxxxx";
*/
const service = "dynamodb";
const region = "us-east-1";
const endpoint = host + "/_api/dynamo";
// secretAccessKey is a required parameter for aws-sdk we recommend you to pass "c8"
const secretAccessKey = "c8";
const accessKeyId = "apikey " + apiKey;
/*
If you are using JWT token use the below instead
const accessKeyId = "bearer " + JWT;
*/
AWS.config.update({
region,
endpoint,
accessKeyId,
secretAccessKey,
});
var dynamodb = new AWS.DynamoDB();
...
...
</script>