Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Moving to the Clouds for a Django site: Amazon S3 & Cloud Front vs. Rackspace Cloud Files & Akamai

Eras
November 19, 2013

Moving to the Clouds for a Django site: Amazon S3 & Cloud Front vs. Rackspace Cloud Files & Akamai

Comparison of the 2 major cloud providers for storing and serving static files and the challenges for a Django site.
This is a presentation for LA Django meetup.

Eras

November 19, 2013
Tweet

Other Decks in Technology

Transcript

  1. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End LA  Django Nov  19  2013 Sep  Dehpour www.linkedin.com/in/sepehr www.github.com/erasmose   Moving  to  the  Clouds:   Amazon  S3  &  Cloud  Front   vs.  Rackspace  Cloud  Files  &  Akamai     Wednesday, November 20, 13
  2. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Sep  Dehpour  is  the  primary  engineer  on  a  Django  site  that  has  over   1.5  million  page  views  per  day.   His  responsibilities  range  from  systems  administration,  Chef   DevOps,  performance  optimizations  to  new  feature  development.   Sep  is  an  avid  skier  and  likes  to  think  he  is  a  good  surfer  too,  but   that  shit  ain't  easy. About  the  presenter Wednesday, November 20, 13
  3. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End In  this  talk:  Comparison  of  the  2  major  cloud  providers   for  storing  and  serving  sta1c  files  and  the  challenges   for  a  Django  site. Rackspace  &  Akamai  vs.  Amazon  &  CloudFront Wednesday, November 20, 13
  4. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Serving  Sta1c  files Tradi1onal Nginx/Apache Cloud CDN Origin Wednesday, November 20, 13
  5. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Storing  &  Serving  Sta1c  files   CDN Origin User Wednesday, November 20, 13
  6. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Comparison  in  glance Pay as you grow from 10¢/GB/Mo Akamai CDN at 12¢/GB at 213 PoP Store files and media of any size Highly scalable, redundant Pay as you grow from 9.5¢/GB/Mo Cloudfront CDN at 12¢/GB Store files and media of any size Highly scalable, redundant Wednesday, November 20, 13
  7. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End CDN  Comparison  in  glance Akamai is delivering 20-30% of web Apple, Netflix, Amazon.com 1,200 points of presence (PoP) But Rackspace plan uses 213 PoP Akamai NetSession Interface peer-to-peer Nasa, PBS 40 super PoP no peer-to-peer Tip:  Use  hQp://www.cdnplanet.com/tools/cdnfinder    to  find  the  CDN  used  to  serve  sta1c  content. Put  the  full  path  to  an  image  or  CSS  file  to  see  what  CDN  is  serving  it.   Wednesday, November 20, 13
  8. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End CDN  Speed  Comparison  1Mb  object Wednesday, November 20, 13
  9. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End CDN  Speed  Comparison  12Kb  object Wednesday, November 20, 13
  10. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End hQp://www.akamai.com/html/technology/visualizing_akamai.html Akamai  Visualizing Wednesday, November 20, 13
  11. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End So  what’s  exactly  on  S3/Cloud  Files? Container{ Containers at the root level holding objects Object { “key”:”path to file to simulate a nested folder structure”, “etag”:MD5 checksum, “content_type”:Mime Type, “ttl”: time to expire on CDN }, ... } Wednesday, November 20, 13
  12. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  13. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  14. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  15. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End CloudFuse S3fs Virtual File System Unlike  tradi1onal  file  systems  that  essen1ally  save  data  to  and  retrieve   data  from  disk,  virtual  filesystems  do  not  actually  store  data  themselves.   They  act  as  a  view  or  transla1on  of  an  exis1ng  file  system  or  storage   device. Wednesday, November 20, 13
  16. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Buggy: CloudFuse S3fs (?) Virtual File System Unlike  tradi1onal  file  systems  that  essen1ally  save  data  to  and  retrieve   data  from  disk,  virtual  filesystems  do  not  actually  store  data  themselves.   They  act  as  a  view  or  transla1on  of  an  exis1ng  file  system  or  storage   device. Wednesday, November 20, 13
  17. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  18. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End http://s3tools.org/s3cmd Run s3cmd --configure Run s3cmd ls to list all your buckets. Make a bucket with s3cmd mb s3://my-new-bucket-name List the contents of the bucket s3cmd ls s3://bucket_name Upload a file into the bucket s3cmd put addressbook.xml s3://logix.cz-test/addrbook.xml Command line S3cmd Wednesday, November 20, 13
  19. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  20. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End import pyrax pyrax.set_credential_file("/home/user/.pyrax.cfg") cf = pyrax.cloudfiles print "list of containers:", cf.list_containers() cont = cf.get_container("my_container") #uploading a folder local = "path to a local folder" cf.sync_folder_to_container(folder_path=local, container=cont, include_hidden=False) Command line Pyrax Wednesday, November 20, 13
  21. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End #uploading file pth = "path to main.css on local" file_name_on_cloud = "static/assets/stylesheets/ main.css" chksum = pyrax.utils.get_checksum(pth) obj = cont.upload_file(pth,obj_name= file_name_on_cloud, etag=chksum) print "Calculated checksum:", chksum print "Stored object etag:", obj.etag Command line Pyrax Wednesday, November 20, 13
  22. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  23. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End from boto.s3.connection import S3Connection from boto.s3.key import Key import sys conn = S3Connection('AWS credentials', 'AWS credentials') bucket = conn.get_bucket('bucketname') rs = bucket.list("Keys starting with this string") for key in rs: print key.name Command line Boto Wednesday, November 20, 13
  24. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  25. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Django (other) Wednesday, November 20, 13
  26. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End #s3utils.py from storages.backends.s3boto import S3BotoStorage class StaticRootS3BotoStorage(S3BotoStorage): location = 'static' class MediaRootS3BotoStorage(S3BotoStorage): location = 'media' ----------------------------------------------------------------------- #settings.py DEFAULT_FILE_STORAGE = "my_project.s3utils.MediaRootS3BotoStorage" STATICFILES_STORAGE = "my_project.s3utils. StaticRootS3BotoStorage" AWS_STORAGE_BUCKET_NAME = storage_bucket_name AWS_BUCKET_NAME = storage_bucket_name AWS_S3_CUSTOM_DOMAIN = custom_domain Django Django Storages Wednesday, November 20, 13
  27. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Always use Django default_storage so you can easily switch the back-end storage from django.core.files.storage import default_storage from django.core.files.base import ContentFile path = default_storage.save('/path/to/file', ContentFile('new content')) path u'/path/to/file' default_storage.size(path) 11 default_storage.open(path).read() 'new content' default_storage.delete(path) default_storage.exists(path) False Django Django Storages Wednesday, November 20, 13
  28. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End But the 3rd party app that we were using did custom file writing instead of using Django default_storage Django Django Storages Wednesday, November 20, 13
  29. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End And we had a few days till deploying Django Django Storages Wednesday, November 20, 13
  30. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Toolsets/libraries Rackspace control panel AWS control panel Web Toolkit Swift Client (written in Python) S3cmd (written in Python) Command line CloudFuse S3fs Virtual File System Pyrax Boto Python Django Cumulus Django Storages Django Go s3 Python (other) Wednesday, November 20, 13
  31. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Go S3: A light wrapper around Python Boto https://github.com/erasmose/go_s3 When to use Go_s3? You have custom file read/write in your apps or 3rd party apps that are not compatible with “Django Storages” and you don’t have time to go through making it use “Django default storage” so it gets compatible with “Django Storages” or You want to have full control over what goes on S3 and its access control (ACL) Python Go S3 Wednesday, November 20, 13
  32. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End Go S3: A light wrapper around Python Boto https://github.com/erasmose/go_s3 #in  your  django  settings: AWS_ACCESS_KEY_ID  =  "your  AWS_ACCESS_KEY_ID" AWS_SECRET_ACCESS_KEY  =  "your  AWS_SECRET_ACCESS_KEY" AWS_STORAGE_BUCKET_NAME  =  "your  AWS_STORAGE_BUCKET_NAME" -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ #inside  a  custom  save()  for  a  Django  model: go_s3.connect_to_s3() try:        go_s3.upload_file(file_full_path,  full_path_s3,  acl='private',   del_after_upload=True)        print  go_s3.get_grants(full_path_on_s3) except:        logger.error("Unexpected  error  dealing  with  s3  upload:  ",   exc_info=True)                         finally:        go_s3.close_connection() Python Go S3 Wednesday, November 20, 13
  33. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End ACL canned access control policy a.  private:  Owner  gets  FULL_CONTROL.  No  one  else  has  any   access  rights. b.  public-­‐read:  Owners  gets  FULL_CONTROL  and  the   anonymous  principal  is  granted  READ  access. c.  public-­‐read-­‐write:  Owner  gets  FULL_CONTROL  and  the   anonymous  principal  is  granted  READ  and  WRITE  access. d.  authenticated-­‐read:  Owner  gets  FULL_CONTROL  and  any   principal  authenticated  as  a  registered  Amazon  S3  user   is  granted  READ  access Python Go S3 Wednesday, November 20, 13
  34. CAPABILITIES Sep Dehpour linkedin.com/in/sepehr github.com/erasmose Intro Tradi1onal  vs.  Cloud Rackspace

     vs.  Amazon Akamai s3  objects Tools End LA  Django Nov  19  2013 Sep  Dehpour www.linkedin.com/in/sepehr www.github.com/erasmose   Thanks  to  TrueCar  for  hos1ng Wednesday, November 20, 13