{"id":1725,"date":"2021-08-21T11:08:12","date_gmt":"2021-08-21T02:08:12","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=1725"},"modified":"2022-04-03T16:00:53","modified_gmt":"2022-04-03T07:00:53","slug":"%e3%80%90dynamodb%e3%80%91aws-sdk-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%9f%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e4%bd%9c%e6%88%90","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=1725","title":{"rendered":"\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210"},"content":{"rendered":"\n<p>\u4eca\u56de\u306fDynamoDB\u3078\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u306a\u304a\u3001\u524d\u63d0\u3068\u3057\u3066\u4ee5\u4e0b\u304c\u884c\u308f\u308c\u3066\u3044\u308b\u4e8b\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u8003<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1712\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011docker\u3092\u4f7f\u7528\u3057\u305fDynamoDB\u69cb\u7bc9<\/a><\/p>\n<\/div>\n\n\n\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u8a00\u8a9e\u306fNode.js\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210<\/h1>\n\n\n\n<p>\u524d\u56de\u4f5c\u6210\u3057\u305f 02_sample_app \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4ee5\u4e0b\u306b index.js\u3001TableCreater.js\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br>TableCreater.js\u306fDynamoDB\u3078\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const DynamoDbSetter = require(&quot;.\/DynamoDbSetter&quot;);\n\nmodule.exports = class TableCreater extends DynamoDbSetter{\n\n    async createTable() {\n\n        \/\/ \u4f5c\u6210\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u5185\u5bb9\u3092\u8a2d\u5b9a\u3059\u308b\u3002\n        let params = {\n            TableName : &quot;Movies&quot;,\n            KeySchema: [       \n                { AttributeName: &quot;year&quot;, KeyType: &quot;HASH&quot;},  \/\/Partition key\n                { AttributeName: &quot;title&quot;, KeyType: &quot;RANGE&quot; }  \/\/Sort key\n            ],\n            AttributeDefinitions: [       \n                { AttributeName: &quot;year&quot;, AttributeType: &quot;N&quot; },\n                { AttributeName: &quot;title&quot;, AttributeType: &quot;S&quot; }\n            ],\n            ProvisionedThroughput: {       \n                ReadCapacityUnits: 10, \n                WriteCapacityUnits: 10\n            }\n        };\n    \n        \/\/ \u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002\n        return await this.dynamodb.createTable(params).promise();\n\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u524d\u56de\u4f5c\u6210\u3057\u305f\u3001DynamoDB\u306e\u8a2d\u5b9a\u3092\u884c\u3046DynamoDbSetter\u3092\u7d99\u627f\u3057\u3066\u3044\u307e\u3059\u3002\u6545\u306b\u3001DynamoDB\u306e\u8a2d\u5b9a\u306f\u89aa\u30af\u30e9\u30b9\u306eDynamoDbSetter\u304c\u884c\u3044\u307e\u3059\u3002<br>\u30c6\u30fc\u30d6\u30eb\u540d\u3092&#8221;Movies&#8221;\u3068\u3057\u3066\u3044\u307e\u3059\u3002<br>\u30d7\u30e9\u30a4\u30de\u30ea\u30fc\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u4eca\u56de\u306f\u8907\u5408\u30d7\u30e9\u30a4\u30de\u30ea\u30fc\u30ad\u30fc\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br>\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u30ad\u30fc\u3092&#8221;year&#8221;\u3001\u30bd\u30fc\u30c8\u30ad\u30fc\u3092&#8221;title&#8221;\u3068\u3057\u3066\u3044\u307e\u3059\u3002<br>&#8220;year&#8221;\u306e\u5c5e\u6027\u306e\u30bf\u30a4\u30d7\u306f\u6570\u5024(N)\u3001&#8221;title&#8221;\u306e\u5c5e\u6027\u306e\u30bf\u30a4\u30d7\u306f\u6587\u5b57\u5217(S)\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br>\u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u306e\u30b9\u30eb\u30fc\u30d7\u30c3\u30c8\u306f\u30ed\u30fc\u30ab\u30eb\u306e\u5834\u5408\u4efb\u610f\u3067\u69cb\u3044\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>\u30d7\u30e9\u30a4\u30de\u30ea\u30fc\u30ad\u30fc\u3001\u5c5e\u6027\u306e\u8aac\u660e\u306f\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u8003<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1596\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011\u69cb\u6210\u8981\u7d20<\/a><\/p>\n<\/div>\n\n\n\n<p>\u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u306e\u30b9\u30eb\u30fc\u30d7\u30c3\u30c8\u306f\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u8003<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1650\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u30e2\u30fc\u30c9\u3068\u306f<\/a><\/p>\n<\/div>\n\n\n\n<h1 class=\"wp-block-heading\">Lambda\u306e\u5b9f\u884c\u95a2\u6570<\/h1>\n\n\n\n<p>index.js\u306fLambda\u3092\u5b9f\u884c\u3059\u308b\u3068\u521d\u3081\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u95a2\u6570\u306b\u306a\u308a\u307e\u3059\u3002<br>\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u51e6\u7406\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const TableCreater = require(&#39;.\/TableCreater&#39;);\n\nexports.handler = async (event, context) =&gt; {\n\n    let tableCreater = new TableCreater();\n    let result = await tableCreater.createTable();\n\n    context.succeed({\n        statusCode: 200,\n        body: result,\n    });\n\n};<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u5b9f\u884c\u3068\u5b9f\u884c\u7d50\u679c<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30ed\u30fc\u30ab\u30eb\u306eLambda\u95a2\u6570\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>curl -d &#39;{}&#39; http:\/\/localhost:9001\/2015-03-31\/functions\/sample\/invocations<\/code><\/pre><\/div>\n\n\n\n<p>\u30ed\u30fc\u30ab\u30eb\u306eLambda\u95a2\u6570\u547c\u3073\u51fa\u3057\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u8003<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1685\" rel=\"noopener\" target=\"_blank\">\u3010Lambda\u3011\u30ed\u30fc\u30ab\u30eb docker Lambda\u74b0\u5883\u69cb\u7bc9<\/a><\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c\u7d50\u679c<\/h2>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>{\n  &quot;statusCode&quot;:200,\n  &quot;body&quot;:{\n    &quot;TableDescription&quot;:{\n      &quot;AttributeDefinitions&quot;:[\n          {&quot;AttributeName&quot;:&quot;year&quot;,&quot;AttributeType&quot;:&quot;N&quot;},\n          {&quot;AttributeName&quot;:&quot;title&quot;,&quot;AttributeType&quot;:&quot;S&quot;}\n      ],\n      &quot;TableName&quot;:&quot;Movies&quot;,\n      &quot;KeySchema&quot;:[\n        {&quot;AttributeName&quot;:&quot;year&quot;,&quot;KeyType&quot;:&quot;HASH&quot;},\n        {&quot;AttributeName&quot;:&quot;title&quot;,&quot;KeyType&quot;:&quot;RANGE&quot;}\n      ],\n      &quot;TableStatus&quot;:&quot;ACTIVE&quot;,\n      &quot;CreationDateTime&quot;:&quot;2021-08-21T00:51:56.225Z&quot;,\n      &quot;ProvisionedThroughput&quot;:{\n        &quot;LastIncreaseDateTime&quot;:&quot;1970-01-01T00:00:00.000Z&quot;,\n        &quot;LastDecreaseDateTime&quot;:&quot;1970-01-01T00:00:00.000Z&quot;,\n        &quot;NumberOfDecreasesToday&quot;:0,\n        &quot;ReadCapacityUnits&quot;:10,\n        &quot;WriteCapacityUnits&quot;:10\n      },\n      &quot;TableSizeBytes&quot;:0,\n      &quot;ItemCount&quot;:0,\n      &quot;TableArn&quot;:&quot;arn:aws:dynamodb:ddblocal:000000000000:table\/Movies&quot;\n    }\n  }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u4eca\u56de\u306eDynamoDB\u3078\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3060\u3051\u3067\u306a\u304f\u5b9f\u969b\u306eAWS Lambda\u3078\u3082\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<br>DynamoDB\u306e\u8a2d\u5b9a\u90e8\u5206\u3092\u5909\u66f4\u3059\u308b\u306e\u307f\u3067\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fDynamoDB\u3078\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":7,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19,20],"tags":[],"class_list":["post-1725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-dynamodb","category-lambda"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1725"}],"version-history":[{"count":6,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1725\/revisions"}],"predecessor-version":[{"id":3420,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1725\/revisions\/3420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/7"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}