{"id":890,"date":"2019-03-09T16:40:27","date_gmt":"2019-03-09T13:40:27","guid":{"rendered":"https:\/\/artem.services\/?p=844"},"modified":"2019-03-12T18:11:14","modified_gmt":"2019-03-12T15:11:14","slug":"aws-ec2-d0-bf-d0-b5-d1-80-d0-b5-d0-b4-d0-ba-d1-80-b0-8c-d0-d0-d1-b5-d0-be-d1-82-s3-d0-b4-d0-to-be-d0-bf-d0-b8-d1-d0-b0-8c-d0-b8-d1-80-d0-be-d0-b2-d0-b5-d1-80","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=890&lang=en","title":{"rendered":"CloudFormation &#8212; Put credentials from S3 in EC2 Instance"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-214 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo.png\" alt=\"\" width=\"975\" height=\"450\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo.png 975w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-300x138.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-768x354.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2018\/11\/AWS-Logo-954x440.png 954w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><\/p>\n<p><span class=\"tlid-translation translation\"><span class=\"\" title=\"\">An example of <strong>CloudFormation<\/strong> for transfer to the inside of <strong>EC2 instance<\/strong> &quot;<strong>ACCESS_KEY<\/strong>&quot; and &quot;<strong>SECRET_KEY<\/strong>&quot; directly from the <strong>IAM<\/strong> to access the <strong>S3 Bucket<\/strong> using <strong>AWS-Cli<\/strong>.<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nAWSTemplateFormatVersion: &quot;2010-09-09&quot;\r\nDescription: 'Auto create VPC with instance'\r\n\r\n########################################### BLOCK WITH ENVIRONMENTS ###########################################\r\nParameters:\r\n\r\n  ProjectName:\r\n    Type: String\r\n    Default: ArtemPool\r\n    Description: Name of project.\r\n\r\n  SSHKeyName:\r\n    Type: String\r\n    Default: artem\r\n    Description: Name of SSH key.\r\n\r\n  Image:\r\n    Type: String\r\n    Default: ami-0ff8a91507f77f867\r\n    Description: Image for instance (Default - Amazon Linux, if you changes it, you must install AWS-Cli manualy)\r\n    ConstraintDescription: (ami-0ff8a91507f77f867 - Amazon Linux)\r\n\r\n  Region:\r\n    Type: String\r\n    Default: us-east-1b\r\n    Description: Region (Default - U.S. Virginia)\r\n\r\n####################################### BLOCK WITH IAM FOR ACCESS TO S3  ######################################\r\n\r\nResources:\r\n  myaccesskey:\r\n    Type: AWS::IAM::AccessKey\r\n    Properties:\r\n      UserName: artem-s3\r\n\r\n########################################## BLOCK WITH EC2 INSTANCES  ##########################################\r\n\r\n  Ec2Instance:\r\n    Type: AWS::EC2::Instance\r\n    Properties:\r\n      ImageId: !Ref Image\r\n      InstanceType: t2.micro\r\n      KeyName: !Ref SSHKeyName\r\n      BlockDeviceMappings:\r\n        -\r\n          DeviceName: \/dev\/sdm\r\n          Ebs:\r\n            VolumeType: io1\r\n            Iops: 200\r\n            DeleteOnTermination: true\r\n            VolumeSize: 20\r\n      UserData:\r\n        Fn::Base64: !Sub ACCESS_KEY=${myaccesskey}&amp;&amp;SECRET_KEY=${myaccesskey.SecretAccessKey}\r\n\r\nOutputs: \r\n  AccessKeyformyaccesskey:\r\n    Value:\r\n      !Ref myaccesskey\r\n  SecretKeyformyaccesskey:\r\n    Value: !GetAtt myaccesskey.SecretAccessKey\r\n\r\n###############################################################################################################\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An example of CloudFormation for transfer to the inside of EC2 instance &quot;ACCESS_KEY&quot; and &quot;SECRET_KEY&quot; directly from the IAM to access the S3 Bucket using AWS-Cli.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[599],"tags":[543,647,649,651,483],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/890"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=890"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":892,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions\/892"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}