{"id":1809,"date":"2021-08-26T09:09:41","date_gmt":"2021-08-26T00:09:41","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=1809"},"modified":"2022-04-03T15:36:02","modified_gmt":"2022-04-03T06:36:02","slug":"%e3%80%90dynamodb%e3%80%91aws-sdk-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%9f%e3%82%b0%e3%83%ad%e3%83%bc%e3%83%90%e3%83%ab%e3%82%bb%e3%82%ab%e3%83%b3%e3%83%80%e3%83%aa%e3%82%a4%e3%83%b3%e3%83%87","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=1809","title":{"rendered":"\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f5c\u6210"},"content":{"rendered":"\n<p>\u524d\u56de\u306f\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u5358\u4e00\u9805\u76ee\u3092\u53d6\u5f97\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u524d\u56de<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1803\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u5358\u4e00\u9805\u76ee\u306e\u53d6\u5f97<\/a><\/p>\n<\/div>\n\n\n\n<p>\u4eca\u56de\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br>\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u7167<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1750\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/a><\/p>\n<\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u8aac\u660e<\/h2>\n\n\n\n<p>\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u307e\u305a\u306f\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br>\u306a\u304a\u3001\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\u3068\u540c\u6642\u306b\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u305f\u5f8c\u306b\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\u306e\u8aac\u660e\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=1734\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011AWS Lambda \u3092\u4f7f\u7528\u3057\u305f DynamoDB \u30c6\u30fc\u30d6\u30eb\u64cd\u4f5c<\/a><\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\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 DynamoDbOperator extends DynamoDbSetter{\n\n    async exec(event) {\n\n        \/\/ \u5b9f\u884c\u5185\u5bb9\n        let params = {\n            TableName : &quot;Musics&quot;,\n            KeySchema: [\n                { AttributeName: &quot;title&quot;, KeyType: &quot;HASH&quot; },  \/\/Partition key\n                { AttributeName: &quot;artist&quot;, KeyType: &quot;RANGE&quot;}  \/\/Sort key\n            ],\n            AttributeDefinitions: [\n                { AttributeName: &quot;title&quot;, AttributeType: &quot;S&quot; },\n                { AttributeName: &quot;artist&quot;, AttributeType: &quot;S&quot; }\n            ],\n            ProvisionedThroughput: {       \n                ReadCapacityUnits: 10, \n                WriteCapacityUnits: 10\n            }\n        };\n\n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.createTable(params).promise();\n\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f5c\u6210<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/h2>\n\n\n\n<p>&#8220;genre&#8221; \u5c5e\u6027\u306b\u3064\u3044\u3066\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br>\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u306e\u6642\u306f\u3001createTable \u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u306e\u5909\u66f4\u306b\u306a\u308b\u306e\u3067\u3001updateTable \u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\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 DynamoDbOperator extends DynamoDbSetter{\n\n    async exec(event) {\n\n        \/\/ \u5b9f\u884c\u5185\u5bb9\n        let params = {\n            TableName : &quot;Musics&quot;,\n            AttributeDefinitions: [\n                { AttributeName: &quot;genre&quot;, AttributeType: &quot;S&quot; }\n            ],\n            GlobalSecondaryIndexUpdates: [\n                {\n                    Create: {\n                        IndexName: &quot;genreIndex&quot;, \n                        KeySchema: [\n                            { AttributeName: &quot;genre&quot;, KeyType: &quot;HASH&quot;},  \/\/Partition key\n                        ],\n                        Projection: {\n                            ProjectionType: &quot;INCLUDE&quot;,\n                            NonKeyAttributes: [&quot;year&quot;]\n                        },\n                        ProvisionedThroughput: {\n                            ReadCapacityUnits: 10, \n                            WriteCapacityUnits: 10\n                        }\n                    }\n                },\n            ],\n        };\n    \n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.updateTable(params).promise();\n\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c\u5185\u5bb9\u306e\u8aac\u660e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">AttributeDefinitions<\/h3>\n\n\n\n<p>\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u30d7\u30e9\u30a4\u30de\u30ea\u30ad\u30fc\u306e\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">KeySchema<\/h3>\n\n\n\n<p>\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u30ad\u30fc\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u30bd\u30fc\u30c8\u30ad\u30fc\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Projection<\/h3>\n\n\n\n<p>\u5c04\u5f71\u3059\u308b\u5c5e\u6027\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br>Projection \u306e ProjectionType \u306e\u6307\u5b9a\u306f\u3044\u304f\u3064\u304b\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002\u4eca\u56de\u306f &#8220;INCLUDE&#8221; \u3092\u6307\u5b9a\u3057\u307e\u3057\u305f\u3002<br>\u3053\u3046\u3059\u308b\u3068\u3001\u30d7\u30e9\u30a4\u30de\u30ea\u30ad\u30fc\u4ee5\u5916\u306e\u5c5e\u6027\u304c\u5c04\u5f71\u3067\u304d\u307e\u3059\u3002\u4eca\u56de\u306f\u5c5e\u6027\u540d &#8220;year&#8221; \u3092\u5c04\u5f71\u3057\u307e\u3059\u3002<br>\u306a\u304a\u3001\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u30d7\u30e9\u30a4\u30de\u30ea\u30ad\u30fc\u5c5e\u6027\u306f\u81ea\u52d5\u7684\u306b\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3078\u5c04\u5f71\u3055\u308c\u307e\u3059\u3002<br>Projection\u3001\u5c04\u5f71\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u53c2\u7167<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1750\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/a><\/p>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">ProvisionedThroughput<\/h3>\n\n\n\n<p>\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u30b9\u30eb\u30fc\u30d7\u30c3\u30c8\u3068\u306f\u5225\u306b\u306a\u308a\u30b0\u30ed\u30fc\u30d0\u30eb\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6bce\u306b\u72ec\u7acb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7d50\u679c<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>{\n    &quot;TableDescription&quot;: {\n        &quot;AttributeDefinitions&quot;: [\n            {\n                &quot;AttributeName&quot;: &quot;artist&quot;,\n                &quot;AttributeType&quot;: &quot;S&quot;\n            },\n            {\n                &quot;AttributeName&quot;: &quot;genre&quot;,\n                &quot;AttributeType&quot;: &quot;S&quot;\n            },\n            {\n                &quot;AttributeName&quot;: &quot;title&quot;,\n                &quot;AttributeType&quot;: &quot;S&quot;\n            }\n        ],\n        &quot;TableName&quot;: &quot;Musics&quot;,\n        &quot;KeySchema&quot;: [\n            {\n                &quot;AttributeName&quot;: &quot;artist&quot;,\n                &quot;KeyType&quot;: &quot;HASH&quot;\n            },\n            {\n                &quot;AttributeName&quot;: &quot;title&quot;,\n                &quot;KeyType&quot;: &quot;RANGE&quot;\n            }\n        ],\n        &quot;TableStatus&quot;: &quot;UPDATING&quot;,\n        &quot;CreationDateTime&quot;: &quot;2021-08-27T08:07:00.984Z&quot;,\n        &quot;ProvisionedThroughput&quot;: {\n            &quot;LastDecreaseDateTime&quot;: &quot;2021-08-27T08:19:04.873Z&quot;,\n            &quot;NumberOfDecreasesToday&quot;: 1,\n            &quot;ReadCapacityUnits&quot;: 5,\n            &quot;WriteCapacityUnits&quot;: 5\n        },\n        &quot;TableSizeBytes&quot;: 0,\n        &quot;ItemCount&quot;: 0,\n        &quot;TableArn&quot;: &quot;arn:aws:dynamodb:ap-northeast-1:081461195071:table\/Musics&quot;,\n        &quot;TableId&quot;: &quot;43b2bf37-3a41-473d-8c60-b553a1e6334f&quot;,\n        &quot;GlobalSecondaryIndexes&quot;: [\n            {\n                &quot;IndexName&quot;: &quot;genreIndex&quot;,\n                &quot;KeySchema&quot;: [\n                    {\n                        &quot;AttributeName&quot;: &quot;genre&quot;,\n                        &quot;KeyType&quot;: &quot;HASH&quot;\n                    }\n                ],\n                &quot;Projection&quot;: {\n                    &quot;ProjectionType&quot;: &quot;INCLUDE&quot;,\n                    &quot;NonKeyAttributes&quot;: [\n                        &quot;year&quot;\n                    ]\n                },\n                &quot;IndexStatus&quot;: &quot;CREATING&quot;,\n                &quot;Backfilling&quot;: false,\n                &quot;ProvisionedThroughput&quot;: {\n                    &quot;NumberOfDecreasesToday&quot;: 0,\n                    &quot;ReadCapacityUnits&quot;: 10,\n                    &quot;WriteCapacityUnits&quot;: 10\n                },\n                &quot;IndexSizeBytes&quot;: 0,\n                &quot;ItemCount&quot;: 0,\n                &quot;IndexArn&quot;: &quot;arn:aws:dynamodb:ap-northeast-1:081461195071:table\/Musics\/index\/genreIndex&quot;\n            }\n        ]\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u6b21\u56de\u306f\u8907\u6570\u306e\u9805\u76ee\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u6b21\u56de<\/span>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=1819\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u8907\u6570\u9805\u76ee\u306e\u53d6\u5f97<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306f\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u5358\u4e00\u9805\u76ee\u3092\u53d6\u5f97\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":976,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19,20],"tags":[],"class_list":["post-1809","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\/1809","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=1809"}],"version-history":[{"count":18,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1809\/revisions"}],"predecessor-version":[{"id":3406,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1809\/revisions\/3406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/976"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}