{"id":1982,"date":"2021-08-29T11:34:16","date_gmt":"2021-08-29T02:34:16","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=1982"},"modified":"2022-04-03T15:16:08","modified_gmt":"2022-04-03T06:16:08","slug":"%e3%80%90dynamodb%e3%80%91aws-sdk-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%9f%e9%a0%85%e7%9b%ae%e3%81%ae%e6%9c%89%e5%8a%b9%e6%9c%9f%e9%99%90%e3%81%ae%e8%a8%ad%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=1982","title":{"rendered":"\u3010DynamoDB\u3011AWS SDK \u3092\u4f7f\u7528\u3057\u305f\u9805\u76ee\u306e\u6709\u52b9\u671f\u9650\u306e\u8a2d\u5b9a"},"content":{"rendered":"\n<p>DynamoDB\u306f\u53e4\u304f\u306a\u3063\u305f\u9805\u76ee\u3092\u81ea\u52d5\u7684\u306b\u524a\u9664\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u8a73\u7d30\u306a\u8aac\u660e\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=1976\" rel=\"noopener\" target=\"_blank\">\u3010DynamoDB\u3011\u671f\u9650\u4ed8\u304d\u306e\u9805\u76ee\u306e\u6307\u5b9a(TTL)<\/a><\/p>\n<\/div>\n\n\n\n<p>\u4eca\u56de\u306f\u5b9f\u969b\u306b\u5c5e\u6027\u3078TTL\u3092\u8a2d\u5b9a\u3057\u3066\u3001\u671f\u9650\u304c\u5207\u308c\u305f\u9805\u76ee\u304c\u81ea\u52d5\u7684\u306b\u524a\u9664\u3055\u308c\u308b\u3053\u3068\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">TTL\u5c5e\u6027\u306e\u8a2d\u5b9a<\/h1>\n\n\n\n<p>Musics \u30c6\u30fc\u30d6\u30eb\u306eTTL\u3092\u6709\u52b9\u306b\u3057\u3001expDate \u3068\u3044\u3046\u5c5e\u6027\u3092TTL\u5c5e\u6027\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/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            TimeToLiveSpecification: {\n                AttributeName: &quot;expDate&quot;,\n                Enabled: true \n            }\n        };\n    \n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.updateTimeToLive(params).promise();\n \n    }\n}<\/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;TimeToLiveSpecification&quot;: {\n        &quot;Enabled&quot;: true,\n        &quot;AttributeName&quot;: &quot;expDate&quot;\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">TTL\u306e\u767b\u9332<\/h1>\n\n\n\n<p>expDate \u306b\u6709\u52b9\u671f\u9650\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u767b\u9332\u3057\u307e\u3059\u300220\u5206\u5f8c\u306b\u524a\u9664\u3055\u308c\u308b\u3088\u3046\u306b\u6709\u52b9\u671f\u9650\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/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        \/\/ 20\u5206\u5f8c\n        let date = new Date();\n        date.setMinutes( date.getMinutes() + 20);\n        let expDate = Math.floor(date.getTime() \/ 1000);\n\n        let params = {\n            TableName : &quot;Musics&quot;,\n            Item:{ \n                &quot;artist&quot;: {&quot;S&quot;:&quot;B&#39;z&quot;},\n                &quot;title&quot;: {&quot;S&quot;: &quot;GREEN&quot;},\n                &quot;expDate&quot;: {&quot;N&quot;: String(expDate)},\n            },\n            ReturnValues: &quot;ALL_OLD&quot;,\n            ReturnConsumedCapacity: &quot;INDEXES&quot;\n        };\n    \n        return await this.dynamodb.putItem(params).promise();\n \n    }\n}<\/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;Attributes&quot;: {\n        &quot;artist&quot;: {\n            &quot;S&quot;: &quot;B&#39;z&quot;\n        },\n        &quot;expDate&quot;: {\n            &quot;N&quot;: &quot;1630206147&quot;\n        },\n        &quot;title&quot;: {\n            &quot;S&quot;: &quot;GREEN&quot;\n        }\n    },\n    &quot;ConsumedCapacity&quot;: {\n        &quot;TableName&quot;: &quot;Musics&quot;,\n        &quot;CapacityUnits&quot;: 1,\n        &quot;Table&quot;: {\n            &quot;CapacityUnits&quot;: 1\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">TTL\u5c5e\u6027\u306e\u8a2d\u5b9a\u60c5\u5831\u78ba\u8a8d<\/h1>\n\n\n\n<p>TTL\u5c5e\u6027\u306e\u60c5\u5831\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/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        };\n    \n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.describeTimeToLive(params).promise();\n \n    }\n}<\/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;TimeToLiveDescription&quot;: {\n        &quot;TimeToLiveStatus&quot;: &quot;ENABLED&quot;,\n        &quot;AttributeName&quot;: &quot;expDate&quot;\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">TTL\u5c5e\u6027\u306e\u8a2d\u5b9a\u524a\u9664<\/h1>\n\n\n\n<p>\u5148\u307b\u3069\u8a2d\u5b9a\u3057\u305fTTL\u306e\u8a2d\u5b9a\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u884c<\/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            TimeToLiveSpecification: {\n                AttributeName: &quot;expDate&quot;,\n                Enabled: false\n            }\n        };\n    \n        \/\/ \u5b9f\u884c\n        return await this.dynamodb.updateTimeToLive(params).promise(); \n    }\n}<\/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;TimeToLiveSpecification&quot;: {\n        &quot;Enabled&quot;: false,\n        &quot;AttributeName&quot;: &quot;expDate&quot;\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u7279\u306b\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DynamoDB\u306f\u53e4\u304f\u306a\u3063\u305f\u9805\u76ee\u3092\u81ea\u52d5\u7684\u306b\u524a\u9664\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":968,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19,20],"tags":[],"class_list":["post-1982","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\/1982","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=1982"}],"version-history":[{"count":18,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1982\/revisions"}],"predecessor-version":[{"id":3394,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/1982\/revisions\/3394"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/968"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}