4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lambdaでマップ型のデータをリスト化しDynamoDBへPOSTする

Posted at

AWS Lambda(Node.js)を使用してDynamoDBにマップ型のデータをリスト化し、DBへ保存する。

sample.js
"use strict";
let AWS = require('aws-sdk');

AWS.config.apiVersions = {
    dynamodb: '2012-08-10'
};

let dynamo = new AWS.DynamoDB();


exports.handler = function(event, context) {

  var param ={
   TableName: "Playlist",
  Item:{
    "sample": { 
         L:[{
              M:{"Test" : {S : event["body-json"].sample["0"].Test}}
        }]}
      },
    };

 dynamo.putItem(param, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

};

.sample["0"]でsampleアイテムのリスト型の0番目の要素を指定し、その中のTestというキーを.Testで指定しています。

4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?