{"id":1347,"date":"2017-10-12T15:25:31","date_gmt":"2017-10-12T15:55:31","guid":{"rendered":"https:\/\/mind4y.com\/itstuff\/?p=1347"},"modified":"2020-03-19T23:24:38","modified_gmt":"2020-03-19T23:54:38","slug":"aws-s3-nojejs-api-quickstart","status":"publish","type":"post","link":"https:\/\/ultering.com\/it4us\/?p=1347","title":{"rendered":"AWS: S3: NOJEJS &#8211; PUTOBJECT"},"content":{"rendered":"<p>Create the permission in IAM:<\/p>\n<pre class=\"programlisting\"><code class=\"nohighlight\">...\r\n{\r\n \"Effect\": \"Allow\",\r\n \"Action\": [\r\n   \"s3:putObject\"\r\n ],\r\n \"Resource\": \"arn:aws:s3:::my_corporate_bucket\/*\"\r\n }\r\n...<\/code><\/pre>\n<p>Tips:<\/p>\n<ul>\n<li>You can get the resource ARN just by clicking the bucket and clicking into the button &#8220;Copy Bucket ARN&#8221;<\/li>\n<li>take a look into the\u00a0<a href=\"http:\/\/docs.aws.amazon.com\/AWSJavaScriptSDK\/latest\/AWS\/S3.html#putObject-property\">link: api on amazon<\/a>\u00a0 the name of the allowed operations are the fuction ones<\/li>\n<li>other way to get the permissions is using the &#8220;simulate policy&#8221; inside the AIM Rule you are creating. ( remember to use the field resource when you have specific rule)<\/li>\n<\/ul>\n<p>To create an object, using the API<\/p>\n<pre class=\"example code\">const aws = require('aws-sdk');<code class=\"javascript\"><span class=\"keyword\">\r\nvar<\/span> s3 = <span class=\"keyword\">new<\/span> aws.S3();\r\n<span class=\"comment\">\/* The following example creates an object. If the bucket is versioning enabled, S3 returns version ID in response. *\/<\/span>\r\n\r\n <span class=\"keyword\">var<\/span> params = {\r\n  Body: <span class=\"xml\"><span class=\"tag\">&lt;<span class=\"title\">Binary<\/span> <span class=\"attribute\">String<\/span>&gt;<\/span>, \r\n  Bucket: \"examplebucket\", \r\n  Key: \"objectkey\"\r\n };\r\n s3.putObject(params, function(err, data) {\r\n   if (err) console.log(err, err.stack); \/\/ an error occurred\r\n   else     console.log(data);           \/\/ successful response\r\n   \/*\r\n   data = {\r\n    ETag: \"\\\"6805f2cfc46c0f04559748bb039d69ae\\\"\", \r\n    VersionId: \"Bvq0EDKxOcXLJXNo_Lkz37eM3R4pfzyQ\"\r\n   }\r\n   *\/\r\n });<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Create the permission in IAM: &#8230; { &#8220;Effect&#8221;: &#8220;Allow&#8221;, &#8220;Action&#8221;: [ &#8220;s3:putObject&#8221; ], &#8220;Resource&#8221;: &#8220;arn:aws:s3:::my_corporate_bucket\/*&#8221; } &#8230; Tips: You can get the resource ARN just by clicking the bucket and clicking into the button &#8220;Copy Bucket ARN&#8221; take a look into the\u00a0link: api on amazon\u00a0 the name of the allowed operations are the fuction ones &#8230; <a href=\"https:\/\/ultering.com\/it4us\/?p=1347\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;AWS: S3: NOJEJS &#8211; PUTOBJECT&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[25,27],"class_list":["post-1347","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-aws","tag-nodejs"],"_links":{"self":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1347"}],"version-history":[{"count":1,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1347\/revisions"}],"predecessor-version":[{"id":2642,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1347\/revisions\/2642"}],"wp:attachment":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}