{"id":4993,"date":"2016-08-25T01:00:13","date_gmt":"2016-08-25T01:00:13","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4993"},"modified":"2020-03-30T02:37:15","modified_gmt":"2020-03-30T02:37:15","slug":"set-up-aws-cli-windows","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/set-up-aws-cli-windows\/","title":{"rendered":"Set up the AWS CLI on Windows"},"content":{"rendered":"<p>Theoretically you can install the AWS CLI<sup><a href=\"#footnote_0_4993\" id=\"identifier_0_4993\" class=\"footnote-link footnote-identifier-link\" title=\"http:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html#install-msi-on-windows\">1<\/a><\/sup> to import JSON files to DynamoDB.<\/p>\n<p>Once you install this, you&#8217;ll want to add it to your path.<\/p>\n<p>To connect, do this:<\/p>\n<pre lang=\"bash\">aws configure\n<\/pre>\n<p>To fill out the prompts, you&#8217;ll need to create a username\/password.<sup><a href=\"#footnote_1_4993\" id=\"identifier_1_4993\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/console.aws.amazon.com\/iam\/home#users\">2<\/a><\/sup>. Then find the region name<sup><a href=\"#footnote_2_4993\" id=\"identifier_2_4993\" class=\"footnote-link footnote-identifier-link\" title=\"http:\/\/docs.aws.amazon.com\/general\/latest\/gr\/rande.html\">3<\/a><\/sup>.<\/p>\n<p>To use DynamoDB, create a table, then create a policy with rights to add\/select from the table<sup><a href=\"#footnote_3_4993\" id=\"identifier_3_4993\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/console.aws.amazon.com\/dynamodb\/home?region=us-east-1#tables:selected=talks\">4<\/a><\/sup>.<\/p>\n<p>The policy will look like this:<\/p>\n<pre>{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n  {\n   \"Effect\": \"Allow\",\n   \"Action\": [\n    \"dynamodb:BatchGetItem\",\n    \"dynamodb:BatchWriteItem\",\n    \"dynamodb:DeleteItem\",\n    \"dynamodb:GetItem\",\n    \"dynamodb:PutItem\",\n    \"dynamodb:Query\",\n    \"dynamodb:UpdateItem\"\n   ],\n   \"Resource\": [\n    \"arn:aws:dynamodb:us-east-1:472846177579:table\/talks\"\n   ],\n   \"Condition\": {\n    \"ForAllValues:StringEquals\": {\n     \"dynamodb:LeadingKeys\": [\n      \"${www.amazon.com:user_id}\"\n     ]\n    }\n   }\n  }\n ]\n}\n<\/pre>\n<p>You can save this in the policy editor<sup><a href=\"#footnote_4_4993\" id=\"identifier_4_4993\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/console.aws.amazon.com\/iam\/home?#policies\">5<\/a><\/sup>, attach policy to the user you made earlier <sup><a href=\"#footnote_5_4993\" id=\"identifier_5_4993\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/console.aws.amazon.com\/iam\/home?#users\/gary\">6<\/a><\/sup>. Alternately, there is a permission called  AmazonDynamoDBFullAccess that you can add.<\/p>\n<p>Then, this will work:<\/p>\n<pre lang=\"bash\">aws dynamodb list-tables\n<\/pre>\n<p>Theoretically this should work:<\/p>\n<pre lang=\"bash\">aws dynamodb batch-write-item --request-items file:\/\/1.json\n<\/pre>\n<p>However, the AWS tool seems to suffer from the disastrous Python unicode problems:<\/p>\n<pre>UnicodeEncodeError: 'ascii' codec can't encode characters in position 3747-3748: ordinal not in range(128)\n<\/pre>\n<p>I went through a few dozen blog posts \/ Github tickets, and nothing solved it.<\/p>\n<p>Rather, I found that once you get this far, it&#8217;s worth just writing Python scripts to upload data:<\/p>\n<pre lang=\"python\">from __future__ import print_function\nimport boto3\nimport json\nimport decimal\n\n# endpoint_url=\"http:\/\/localhost:8000\"\ndynamodb = boto3.resource('dynamodb', region_name='us-east-1')\n\ntable = dynamodb.Table('talks')\n\nwith open(\"d:\\\\projects\\\\image-annotation\\\\data\\\\talks\\\\json\\\\1\\\\1.json\") as json_file:\n  row = json.load(json_file, parse_float = decimal.Decimal)\n  table.put_item(\n    Item={\n      'id_i': str(row['id_i'])\n    }\n  )\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_4993\" class=\"footnote\">http:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html#install-msi-on-windows<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_1_4993\" class=\"footnote\">https:\/\/console.aws.amazon.com\/iam\/home#users<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_1_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_2_4993\" class=\"footnote\">http:\/\/docs.aws.amazon.com\/general\/latest\/gr\/rande.html<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_2_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_3_4993\" class=\"footnote\">https:\/\/console.aws.amazon.com\/dynamodb\/home?region=us-east-1#tables:selected=talks<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_3_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_4_4993\" class=\"footnote\">https:\/\/console.aws.amazon.com\/iam\/home?#policies<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_4_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_5_4993\" class=\"footnote\">https:\/\/console.aws.amazon.com\/iam\/home?#users\/gary<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_5_4993\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>How to set up the AWS CLI on Windows and start importing data to DynamoDB<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,12],"tags":[71,447],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4993"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4993"}],"version-history":[{"count":1,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4993\/revisions"}],"predecessor-version":[{"id":6442,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4993\/revisions\/6442"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}