{"id":2152,"date":"2021-09-04T18:33:14","date_gmt":"2021-09-04T09:33:14","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=2152"},"modified":"2022-04-03T15:03:01","modified_gmt":"2022-04-03T06:03:01","slug":"%e3%80%90dynamodb%e3%80%91aws-sdk-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%9f%e6%9d%a1%e4%bb%b6%e4%bb%98%e3%81%8d%e8%a4%87%e6%95%b0%e9%a0%85%e7%9b%ae%e3%81%ae%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=2152","title":{"rendered":"\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u6761\u4ef6\u4ed8\u304d\u8907\u6570\u9805\u76ee\u306e\u53d6\u5f97"},"content":{"rendered":"\n<p>\u524d\u56de\u306f\u8907\u6570\u9805\u76ee\u306e\u53d6\u5f97\u306b\u306f\u30af\u30a8\u30ea\u30fc\u3092\u4f7f\u7528\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=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\n\n\n<p>\u4eca\u56de\u3082\u30af\u30a8\u30ea\u30fc\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u30af\u30a8\u30ea\u30fc\u306f\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u9805\u76ee\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br>\u30d1\u30fc\u30c6\u30b7\u30e7\u30f3\u30ad\u30fc\u306f\u6761\u4ef6\u3092\u6307\u5b9a\u3067\u304d\u307e\u305b\u3093\u304c\u3001\u30bd\u30fc\u30c8\u30ad\u30fc\u306b\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u9805\u76ee\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u306e\u5185\u5bb9<\/h1>\n\n\n\n<p>Musics\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066\u30af\u30a8\u30ea\u30fc\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<br>\u30c6\u30fc\u30d6\u30eb\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"987\" height=\"441\" src=\"https:\/\/dennie.tokyo\/it\/wp-content\/uploads\/2021\/08\/table.png\" alt=\"\" class=\"wp-image-2013\" srcset=\"https:\/\/dennie.tokyo\/it\/wp-content\/uploads\/2021\/08\/table.png 987w, https:\/\/dennie.tokyo\/it\/wp-content\/uploads\/2021\/08\/table-300x134.png 300w, https:\/\/dennie.tokyo\/it\/wp-content\/uploads\/2021\/08\/table-768x343.png 768w\" sizes=\"auto, (max-width: 987px) 100vw, 987px\" \/><\/figure>\n\n\n\n<p>artist: \u30d1\u30fc\u30c6\u30b7\u30e7\u30f3\u30ad\u30fc<br>title: \u30bd\u30fc\u30c8\u30ad\u30fc<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u30bb\u30ab\u30f3\u30c0\u30ea\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f5c\u6210<\/h1>\n\n\n\n<p>\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\u306e\u4f5c\u6210\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=1809\" rel=\"noopener\" target=\"_blank\">\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<\/a><\/p>\n<\/div>\n\n\n\n<p>\u4ee5\u4e0b\u3092\u5b9f\u884c\u3057\u3001\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<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                { AttributeName: &quot;title&quot;, AttributeType: &quot;S&quot; },\n            ],\n            GlobalSecondaryIndexUpdates: [\n                {\n                    Create: {\n                        IndexName: &quot;genre_title_index&quot;, \n                        KeySchema: [\n                            { AttributeName: &quot;genre&quot;, KeyType: &quot;HASH&quot;},  \/\/Partition key\n                            { AttributeName: &quot;title&quot;, KeyType: &quot;RANGE&quot; }  \/\/Sort key\n                        ],\n                        Projection: {\n                            ProjectionType: &quot;INCLUDE&quot;,\n                            NonKeyAttributes: [&quot;sngsCnt&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    }\n}<\/code><\/pre><\/div>\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\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<p>genre: \u30d1\u30fc\u30c6\u30b7\u30e7\u30f3\u30ad\u30fc<br>title: \u30bd\u30fc\u30c8\u30ad\u30fc<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u6761\u4ef6\u3092\u6307\u5b9a\u3057\u3066\u5b9f\u884c<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/h2>\n\n\n\n<p>\u30d1\u30fc\u30c6\u30b7\u30e7\u30f3\u30ad\u30fc\u3067\u30af\u30a8\u30ea\u30fc\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002genre \u304c &#8220;POP&#8221; \u3067\u3001title \u304c &#8220;GEEN&#8221; \u3067\u59cb\u307e\u308b\u9805\u76ee\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<br>Lambda\u95a2\u6570\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\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        let genre = event.genre;\n        let title = event.title;\n        \n        \/\/ \u5b9f\u884c\u5185\u5bb9\n        let params = {\n            TableName : &quot;Musics&quot;,\n            IndexName: &#39;genre_title_index&#39;,\n            KeyConditionExpression: &#39;#genre = :genreValue AND begins_with(#title, :titleValue)&#39;,\n            ExpressionAttributeNames: {\n                &#39;#genre&#39;: &#39;genre&#39;,\n                &#39;#title&#39;: &#39;title&#39;,\n            },\n            ExpressionAttributeValues: {\n                &#39;:genreValue&#39;: {&#39;S&#39;: genre},\n                &#39;:titleValue&#39;: {&#39;S&#39;: title},\n            }\n        };\n  \n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.query(params).promise();\n \n    }\n \n}<\/code><\/pre><\/div>\n\n\n\n<p>Lambda\u95a2\u6570\u5b9f\u884c\u30b3\u30de\u30f3\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002AWS CLI \u304b\u3089\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>aws lambda invoke --function-name DynamoDbFunction --payload $(echo &#39;{ &quot;genre&quot;: &quot;POP&quot;, &quot;title&quot;: &quot;GREEN&quot;}&#39; | base64) outputfile.txt<\/code><\/pre><\/div>\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;Items&quot;: [\n        {\n            &quot;artist&quot;: {\n                &quot;S&quot;: &quot;YUI&quot;\n            },\n            &quot;sngsCnt&quot;: {\n                &quot;N&quot;: &quot;18&quot;\n            },\n            &quot;genre&quot;: {\n                &quot;S&quot;: &quot;POP&quot;\n            },\n            &quot;title&quot;: {\n                &quot;S&quot;: &quot;GREEN GARDEN POP&quot;\n            }\n        }\n    ],\n    &quot;Count&quot;: 1,\n    &quot;ScannedCount&quot;: 1\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\u30c6\u30fc\u30d6\u30eb\u304b\u3089scan\u3092\u4f7f\u7528\u3057\u3066\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=2128\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305fscan\u306e\u5b9f\u884c<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306f\u8907\u6570\u9805\u76ee\u306e\u53d6\u5f97\u306b\u306f\u30af\u30a8\u30ea\u30fc\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":1258,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19,20],"tags":[],"class_list":["post-2152","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\/2152","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=2152"}],"version-history":[{"count":8,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/2152\/revisions"}],"predecessor-version":[{"id":3383,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/2152\/revisions\/3383"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/1258"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}