Skip to content

Instantly share code, notes, and snippets.

@garnaat
Created September 15, 2010 04:48
Show Gist options
  • Save garnaat/580250 to your computer and use it in GitHub Desktop.
Save garnaat/580250 to your computer and use it in GitHub Desktop.
Use IAM/boto to provide access to EC2 and S3
"""
IAM boto examples:
In this example we create a group that provides access
to all EC2 and S3 resources and actions and then add a
user to that group.
"""
import boto
#
# First create a connection to the IAM service
#
iam = boto.connect_iam()
#
# Now create a group for EC2/S3 users.
# This group will allow members to use all EC2 and S3 functionality
#
ec2s3_policy = """
{
"Statement":[{
"Effect":"Allow",
"Action":["ec2:*", "s3:*"],
"Resource":"*"
}
]
}"""
response = iam.create_group('EC2-S3-Users')
response = iam.put_group_policy('EC2-S3-Users', 'EC2andS3', ec2s3_policy)
#
# Now create a user and place him in the EC2 group.
#
response = iam.create_user('Bob')
user = response.user
response = iam.add_user_to_group('EC2-S3-Users', 'Bob')
#
# Create AccessKey/SecretKey pair for Bob
#
response = iam.create_access_key('Bob')
access_key = response.access_key_id
secret_key = response.secret_access_key
#
# create connection to EC2 as user Bob
#
ec2 = boto.connect_ec2(access_key, secret_key)
#
# Now do some crazy EC2 shit
#
@garnaat
Copy link
Author

garnaat commented Sep 15, 2010

Simple example of Amazon Web Services Identity and Access Management (IAM) service in boto.

@grayaii
Copy link

grayaii commented Jun 12, 2013

Awesome! Thanks for this snippet of code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment