{"id":277,"date":"2020-06-06T18:41:48","date_gmt":"2020-06-06T16:41:48","guid":{"rendered":"https:\/\/camilomatajira.wordpress.com\/?p=277"},"modified":"2020-06-06T18:41:48","modified_gmt":"2020-06-06T16:41:48","slug":"creating-a-static-website-with-terraform-and-aws-s3","status":"publish","type":"post","link":"https:\/\/camilo.matajira.com\/?p=277","title":{"rendered":"Creating a static website with Terraform and AWS&#8217; S3"},"content":{"rendered":"\n<p>In this project I want to provision an S3 bucket with Terraform, and then use the AWS cli to copy the content of the web page to the bucket. <\/p>\n\n\n\n<p>You can check the source code <a href=\"https:\/\/gitlab.com\/ca.matajira966\/terraform_create_static_website_s3\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps<\/h2>\n\n\n\n<p>The steps to run the project are the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#! \/bin\/bash\n\npip3 install awscli==1.18.74\n\nexport AWS_ACCESS_KEY_ID=XXXXXXXXXXX\nexport AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXX\nexport S3_BUCKET_NAME=camilomatajira-bucket.com\nexport AWS_REGION=eu-west-3\n\n# Launch terraform\nterraform init\nterraform plan --out my_plan\nterraform apply my_plan\n\n# Copy the content\naws s3 cp .\/index.html s3:\/\/${S3_BUCKET_NAME}\/index.html\n\n# To test if it works\ncurl http:\/\/${S3_BUCKET_NAME}.s3-website.${AWS_REGION}.amazonaws.com\n\n# TO DESTROY\n# terraform destroy\n\n<\/pre><\/div>\n\n\n<p>The content of the terraform file is the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nresource &quot;aws_s3_bucket&quot; &quot;b&quot; {\n  bucket = &quot;camilomatajira-bucket.com&quot;\n  acl    = &quot;public-read&quot;\n  force_destroy = true\n  policy = &lt;&lt;EOF\n{ \n  &quot;Version&quot;:&quot;2012-10-17&quot;,\n  &quot;Statement&quot;:&#x5B;{\n    &quot;Sid&quot;:&quot;PublicReadGetObject&quot;,\n        &quot;Effect&quot;:&quot;Allow&quot;,\n      &quot;Principal&quot;: &quot;*&quot;,\n      &quot;Action&quot;:&#x5B;&quot;s3:GetObject&quot;],\n      &quot;Resource&quot;:&#x5B;&quot;arn:aws:s3:::camilomatajira-bucket.com\/*&quot;\n      ]\n    } \n  ] \n} \nEOF\n\n  website {\n    index_document = &quot;index.html&quot;\n    error_document = &quot;error.html&quot;curl http:\/\/${S3_BUCKET_NAME}.s3-website.${AWS_REGION}.amazonaws.com\n  }\n}\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>In this project I want to provision an S3 bucket with Terraform, and then use the AWS cli to copy the content of the web page to the bucket. You can check the source code here. Steps The steps to run the project are the following: The content of the terraform file is the following:<\/p>\n","protected":false},"author":2,"featured_media":278,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,40,59,69],"class_list":["post-277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","tag-aws","tag-iam","tag-s3","tag-terraform"],"_links":{"self":[{"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/posts\/277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277"}],"version-history":[{"count":0,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/posts\/277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=\/wp\/v2\/media\/278"}],"wp:attachment":[{"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/camilo.matajira.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}