In the previous article, bean reviewed how to create a basic user group and user and bind the MFA device. In this article, we will look at how to customize roles ), the EC2 instance bound to this role will automatically have the permission to access the S3 bucket. Bean also conducted a comparative test to verify whether the custom role is working.
First, open Iam and create new role.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/07/wKioL1OyM3OTpN78AABDiiaKC2Y737.png "style =" float: none; "Title =" 1.png" alt = "wkiol1oym3otpn78aabdiiakc2y737.png"/>
Named EC2-S3
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/07/wKioL1OyM3Sw3OoTAAAxU913j1c655.png "style =" float: none; "Title =" 2.png" alt = "wkiol1oym3sw3ootaaaxu913j1c655.png"/>
Select Amazon EC2. Note that "allow EC2 instance representatives to access other services"
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/07/wKiom1OyM6WAggKCAAByvd16wOU802.png "style =" float: none; "Title =" 3.png" alt = "wkiom1oym6waggkcaabyvd16wou802.png"/>
Select S3 full access for the Template
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/08/wKiom1OyM6ezMZWpAACOAAAEcfQ157.png "style =" float: none; "Title =" 4.png" alt = "wkiom1oym6ezmzwpaacaaaecfq157.png"/>
Automatically Generated JSON statement
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/08/wKiom1OyM6njrsG7AABF563lXZ4373.png "style =" float: none; "Title =" 5.png" alt = "wkiom1oym6njrsg7aabf563lxz4373.png"/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/07/wKioL1OyM3ygbXViAAA3__JGyYQ925.png "style =" float: none; "Title =" 6.png" alt = "wkiol1oym3ygbxviaaa31_jgyyq925.png"/>
Created
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/07/wKioL1OyM3zSMZ5RAAAbm1Z2Gjc647.png "style =" float: none; "Title =" 7.png" alt = "wkiol1oym3jwz5raaabm1z2gjc647.png"/>
Next, let's do a test. I already have a web server EC2 instance, and I ran a Wordpress blog on it. By default, I didn't assign a role to him when I created it. That is to say, he has no permission to access other services on AWS.
Next, I want to create a new instance and assign a custom role to it.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/08/wKiom1OyM63wZktiAABuRcfBpXs568.png "style =" float: none; "Title =" 8.png" alt = "wkiom1oym63wzktiaaburcfbpxs568.png"/>
Create a Linux AMI instance
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/07/wKioL1OyM4CgpQHTAAA2F3s_k-E335.png "style =" float: none; "Title =" 9.png" alt = "wKioL1OyM4CgpQHTAAA2F3s_k-E335.png"/>
Free Micro type
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/08/wKioL1OyM4KBVk0DAACcMMJLsxc224.png "style =" float: none; "Title =" 10.png" alt = "wkiol1oym4kbvk0daaccmmjlsxc224.png"/>
Iam role select a custom ec2-s3
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/09/wKiom1OyM7SDF5hqAACq7aKpGL8193.png "style =" float: none; "Title =" 11.png" alt = "wkiom1oym7sdf5hqaacq7akpgl8193.png"/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/08/wKioL1OyM4fRSeBNAABcPE7Xdrs943.png "style =" float: none; "Title =" 12.png" alt = "wkiol1oym4frsebnaabcpe7xdrs943.png"/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/08/wKioL1OyM4mTQf98AABBQy96VzI231.png "style =" float: none; "Title =" 13.png" alt = "wkiol1oym4mt000098aabbqy96vzi231.png"/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/09/wKiom1OyM7ry7avpAACP8Y8TzlE364.png "style =" float: none; "Title =" 14.png" alt = "wkiom1oym7ry7avpaacp8y8tzle364.png"/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/08/wKioL1OyM43CFrEjAABkhVi7yOI019.png "style =" float: none; "Title =" 15.png" alt = "wkiol1oym43cfrejaabkhvi7yoi019.png"/>
The creation process is very simple and will not be repeated.
After the creation is complete, log in from putty with his public IP address. Remember to select the corresponding certificate for SSH authentication.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/09/wKiom1OyM72TC1BgAABSf4Yt2Vg735.png "style =" float: none; "Title =" 16.png" alt = "wkiom1oym72tc1bgaabsf4yt2vg735.png"/>
After logging in, check the Python version (installed by default)
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/08/wKioL1OyM4_Sfry2AAAHBJkSNwU546.png "style =" float: none; "Title =" 17.png" alt = "wkiol1oym4_sfry2aaahbjksnwu546.png"/>
Then install Pip
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/09/wKiom1OyM7_wkWHzAAAOr5Tjpz8588.png "style =" float: none; "Title =" 18.png" alt = "wkiom1oym7_wkwhzaaaor5tjpz8588.png"/>
Verify successful installation
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/08/wKioL1OyM5Hg2YIWAAANaVtXvbY563.png "style =" float: none; "Title =" 19.png" alt = "wkiol1oym5hg2yiwaaanavtxvby563.png"/>
Upgrade Pip to the latest version.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/09/wKiom1OyM8LyGhZAAAA_XKbHgCo428.png "style =" float: none; "Title =" javaspng" alt = "wkiom1oym8lyghzaaaa_xkbhgco428.png"/>
Then install the latest awscli command line tool through PIP
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/08/wKioL1OyM5SiVB_AAAAgSeXcr-k058.png "style =" float: none; "Title =" 21.png" alt = "wKioL1OyM5SiVB_AAAAgSeXcr-k058.png"/>
After installation, check whether S3 can be accessed. After successful access, my S3 bucket is listed.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/09/wKiom1OyM8OydsKmAAAI8rQ5VJY500.png "style =" float: none; "Title =" 22.png" alt = "wkiom1oym8oydskmaaai8rq5vjy500.png"/>
Check the console!
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/0A/wKioL1OyNqrARn5OAAAlkwPjq8o318.png "Title =" 24.png" alt = "wkiol1oynqrarn5oaaalkwpjq8o318.png"/>
In the same way, log on to my web server, install the command line tool, and run the command. An error is returned! No access permission.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/09/wKiom1OyM8TSb-YkAAANSNcoC_M084.png "style =" float: none; "Title =" 23.png" alt = "wKiom1OyM8TSb-YkAAANSNcoC_M084.png"/>
Comparison Test successful!
This article from the "Mapo tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1433017