Managing AWS cloud with Python




Rohit Gupta

Developer @plivo

@rohit01

1 min. Say the topic





*AWS - Amazon Web Service

Presenter Notes

@rohit01

  • FOSS enthusiast
  • Fedora Ambassador
  • Founded LUG, KGEC
  • Python lover
  • Cloud Architect @plivo

2 min. Dont look at slide. Seamless!

Presenter Notes

Agenda

  • Cloud computing
  • Boto
  • Typical scenario: >>infrastructure
  • Problems associated
  • Solution
  • Boto code examples

1 min. Elaborate topics in full file

Presenter Notes

Cloud Computing

5 min. Our knowledge of Cloud computing is very limited. Play the video

Future comparision

Presenter Notes

Benefits

chart1

3 min. Traditional datacenters require frequent update. With AWS its just a matter of calling the API



Disclainder: The above image is taken from AWS website

Presenter Notes

AWS Terminology

  • EC2 - Elastic Compute Cloud
    • Seven regions
    • Zones within regions
    • Instance
    • AMI - Amazon Machine Images
  • ELB - Elastic Load Balancer
  • S3 - Scalable Storage in the Cloud
  • Route 53

5 min. 3 in US, 1 EU, 1 Singapore, 1 SA, 1 Tokyo

Presenter Notes

pip install boto

Presenter Notes

Launch instance

 1 from boto.ec2 import connect_to_region
 2 def get_connection(region):
 3     conn = connect_to_region(
 4             region_name=region,
 5             aws_access_key_id='<AWS_ACCESS_KEY_ID>',
 6             aws_secret_access_key='<AWS_SECRET_ACCESS_KEY>'
 7     )
 8     return conn
 9 
10 def launch_instance(region, ami_image_id):
11     conn = get_connection(region)
12     conn.run_instances(ami_image_id)

Presenter Notes

Typical scenario: >>Infrastructure


  • 50 servers
  • 20 different types


Manage cloud Resources !

Presenter Notes

ps -ef | grep admin

  • Maintenance
  • 20 image ids (AMI id)
  • > 50 backups
  • Code updates
  • Monitoring

Presenter Notes

| more

  • Outages
  • ELB: load balancers
  • Auto-scaling
  • Failover

Presenter Notes

Problem: Resource id's


1 def launch_instance(region, ami_image_id):
2     conn = get_connection(region)
3     reservation = conn.run_instances(ami_image_id)
4     instance = reservation.instances[0]
5     print instance.id
  • instance.id: i-e9ovilp5
  • ami_image_id: ami-80e915e9

Presenter Notes

Solution

  • Create Roles for each server type
  • Tag Resources

Presenter Notes

Solution

  • Create Roles for each server type
  • Tag Resources


Simplicity

  • Find resources

Presenter Notes

Fetch AMI id

1 def get_ami_id(region, role):
2     conn = get_connection(region)
3     my_images = conn.get_all_images(owners='<ACCOUNT_NO>')
4     for image in my_images:
5         if image.tags['role'] == role:
6             return image.id
7     return None

Presenter Notes

Fetch AMI id

1 def get_ami_id(region, role):
2     conn = get_connection(region)
3     my_images = conn.get_all_images(owners='<ACCOUNT_NO>')
4     for image in my_images:
5         if image.tags['role'] == role:
6             return image.id
7     return None

Launch Instance

1 def launch_instance(region, role):
2     conn = get_connection(region)
3     ami_id = get_ami_id(region, role)
4     reservation = conn.run_instances(ami_id)
5     instance = reservation.instances[0]
6     instance.add_tag('role', role)
7     print 'Instance launched!'

Presenter Notes

Syntax: Resource Tagging

  • Get the Resource object from AWS using boto
  • Add the tag using the Syntax given below:



<resource_object>.add_tag('<key>', '<value>')

Presenter Notes

AWS Outage

  • Instance
  • EBS
  • DNS
  • ELB
  • API calls

Presenter Notes

1 Minute; Every minute

  • Offline data store
  • Redis
  • Auto + manual failovers

Presenter Notes

Failover

  • Identify
  • Launch
  • Recover

Presenter Notes

Chaos Monkey

AutomaticFailover

Presenter Notes

questions

Presenter Notes

Thank You


Rohit Gupta

Developer @plivo

Email: [email protected]

Ph: +91-8496035658

Slide link: https://bit.ly/plivoaws

Presenter Notes