Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way is to use <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingIAM.html#UsingIAMrolesWithAmazonEC2Instances">instance profiles</a>. The basic idea is:</p> <ul> <li>Create an instance profile</li> <li>Create a new IAM role</li> <li><p>Assign a policy to the previously created role, for example:</p> <p>{ "Statement": [ { "Sid": "Stmt1369049349504", "Action": "sqs:<em>", "Effect": "Allow", "Resource": "</em>" } ] }</p></li> <li><p>Associate the role and instance profile together.</p></li> <li>When you start a new EC2 instance, make sure you provide the instance profile name.</li> </ul> <p>If all works well, and the library you use to connect to AWS services from within your EC2 instance supports retrieving the credentials from the instance meta-data, your code will be able to use the AWS services.</p> <p>A complete example taken from the boto-user mailing list:</p> <p>First, you have to create a JSON policy document that represents what services and resources the IAM role should have access to. for example, this policy grants all S3 actions for the bucket "my_bucket". You can use whatever policy is appropriate for your application.</p> <pre><code>BUCKET_POLICY = """{ "Statement":[{ "Effect":"Allow", "Action":["s3:*"], "Resource":["arn:aws:s3:::my_bucket"]}]}""" </code></pre> <p>Next, you need to create an Instance Profile in IAM.</p> <pre><code>import boto c = boto.connect_iam() instance_profile = c.create_instance_profile('myinstanceprofile') </code></pre> <p>Once you have the instance profile, you need to create the role, add the role to the instance profile and associate the policy with the role.</p> <pre><code>role = c.create_role('myrole') c.add_role_to_instance_profile('myinstanceprofile', 'myrole') c.put_role_policy('myrole', 'mypolicy', BUCKET_POLICY) </code></pre> <p>Now, you can use that instance profile when you launch an instance:</p> <pre><code>ec2 = boto.connect_ec2() ec2.run_instances('ami-xxxxxxx', ..., instance_profile_name='myinstanceprofile') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload