如何将Dynamo DB与Express Angle App连接

时间:2018-11-21 10:38:12

标签: node.js angular express amazon-dynamodb dynamo-local

我现在创建简单的angular 7表单和后端表达节点应用程序,我想将数据存储到Database(Dynamodb)中,因此如何将其与从前端获取输入并将数据存储到db的应用程序连接

    app.post('/business/add', (req, res) => {
var table = "business";
var person_name = req.body.person_name;
var business_name = req.body.business_name;
var business_gst_number = req.body.business_gst_number;

var params = {
    Item: {
        "person_name": {
       S: person_name

      }, 
      "business_name": {
       S: business_name
      }, 
      "business_gst_number": {
       N: business_gst_number
      }
    }, 
    ReturnConsumedCapacity: "TOTAL", 
    TableName: "business"
   };


console.log("Adding a new item...");
doClient.putitem(params, function(err, data) {
    if (err) {
        console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("Added item:", JSON.stringify(data, null, 2));
    }
});

    // console.log(req.body);
    // res.json({});
});`

1 个答案:

答案 0 :(得分:1)

使用Angular http服务向服务器(localhost / ip / domain)发出请求。 Angular Http

在服务器端配置aws-sdk。Configure aws-sdk

一旦配置了aws_access_key_id和aws_secret_access_key,您就可以连接到DynamoDb

有关CRUD ops的nodejs,请参考此Dynamo官方数据库文档。 DynamoDb Nodejs