-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDK-NodeJS
69 lines (54 loc) · 1.45 KB
/
SDK-NodeJS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
AWS SDK for Node:
(installation: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-started-nodejs.html)
/> npm install aws-sdk
create a user and attach a DynamoDB full access role
/> npm install uuid
/> aws configure
/> vim ddb_createtable.js
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'us-east-2'});
// Create the DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
AttributeDefinitions: [
{
AttributeName: 'CUSTOMER_ID',
AttributeType: 'N'
},
{
AttributeName: 'CUSTOMER_NAME',
AttributeType: 'S'
}
],
KeySchema: [
{
AttributeName: 'CUSTOMER_ID',
KeyType: 'HASH'
},
{
AttributeName: 'CUSTOMER_NAME',
KeyType: 'RANGE'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
TableName: 'CUSTOMER_LIST',
StreamSpecification: {
StreamEnabled: false
}
};
// Call DynamoDB to create the table
ddb.createTable(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Table Created", data);
}
});
/> node ddb_createtable.js
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/js-sdk-dg.pdf ((( SDK Developer Guide )))
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-examples-using-tables.html