1 / 30

Amazon AWS – brief intro

Amazon AWS – brief intro. By “PJ” (JP on meetup.com) iOS and PHP developer, and occasional lawyer Contact me via: pj@pjebs.com.au. AWS - Objectives.

thor
Download Presentation

Amazon AWS – brief intro

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Amazon AWS – brief intro • By “PJ” (JP on meetup.com) • iOS and PHP developer, and occasional lawyer • Contact me via: pj@pjebs.com.au

  2. AWS - Objectives • AWS is a set of products on the cloud that helps 3rd party business' host their web services without having to buy their own infrastructure (i.e. web servers etc) What I will cover: • S3, EC2, Route 53, RDS, ELB, Elastic Beanstalk • How all the products fit together • Secret Bonus Topic • The AWS documentation is REALLY REALLY BAD • Register and you can get basic use for free (1 year)

  3. AWS

  4. S3 – Simple Static Storage • Online hard drive for files (any files) • Your files can be private or public • Great for storing static content • Javascript, html, css, images • In fact it is the industry standard to store static content in a separate server

  5. Static Server for meetup.com • Very real possibility that meetupstatic.com points to S3 address

  6. S3 – Create a bucket You must create a BUCKET (like a drive) to store your files

  7. Store Files in Bucket • All files are identified by its BUCKET and KEY • The “Key” is the folders + filename + file extension • All “Folders” are actually illusions. • eg. • BUCKET = “samplebucket123321” • KEY = “favicon.ico”

  8. S3 – Accessing files using URL All files in S3 can be accessed using its individual URL. If you make the files “public” or make the “folder” public, you can use those URL's in your website.

  9. S3 – accessing files using URL You can also make the bucket into “static website hosting” mode. This link is optimised for static delivery. The previous link (https) is your only choice if your website is using a https connection

  10. S3 – accessing files using PHP SDK

  11. S3 - Summary Great for storing • Static data (images, css, javascript, html) • Instead of storing BLOB data in a database, you can reduce pressure on database server by storing it on S3 • Create a space for your users to store files (that's what dropbox does) • Very very simple and straightforward • They provide HTTPS access for no extra cost • Unbelievably cheap product • NOTE: You can't delete a bucket unless you delete all files inside first

  12. Elastic Beanstalk • Provides PaaS interface (like Google App Engine and Heroku) • Connects EC2, RDS, ELB together • You don't need to use Elastic Beanstalk but it is free • You only pay for the underlying infrastructure that is used (i.e. EC2 instances) • Provides really convenient way to upload your software

  13. Elastic Beanstalk RDS (DB Server) ELB Load Balancer EC2 Incoming Traffic EC2 EC2 EC2 Makes scaling easy

  14. Elastic Beanstalk You create a new “Environment” with your choice in OS (i.e. Linux (different variants) or Windows) and your preferred configuration (i.e. PHP/Apache) • Create a unique name for the Environment • The website will be X.elasticbeanstalk.com • Chose option to also make a separate database server using RDS product • Chose your instance type (t1.micro is free for 1st year) • Make sure you set up a key_pair so you can SSH into your EC2 instance • Chose your RDS database type (i.e. mysql) and root database name and password and size of database

  15. EC2 instance types https://aws.amazon.com/ec2/instance-types/ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts_micro_instances.html http://haydenjames.io/when-to-use-amazon-ec2-t1-micro-instances/

  16. Elastic Beanstalk • After it creates the EC2 instance etc. you will be able to upload your website using its Deployment Service. • You need to zip up your PHP files AND not the folder containing your PHP files • This is much more convenient than accessing your EC2 instance using SSH, setting up Apache and then uploading your PHP files. • You can also set up ELB (Load balancer) and configure it so you set limits on how many EC2 instances are created and when to kick-start them (i.e. when traffic is peaking, CPU will be close to 100%)

  17. Elastic Beanstalk • RDS will provide you with an endpoint to use in your PHP programs to connect to your database. • If you want, you can host database yourself in same instance OR create a new instance specifically for MySQL server • Be careful not to store files on EC2 server because it could get shut down anytime. Always store permanent data in S3, RDS or EBS (Elastic Block Store)

  18. Elastic Beanstalk – Optimising Costs • If you have a lot of traffic, you must optimise the way scaling is done. • You could save $100-1000 per month if you do it right. • There are many ways to scale: Increase capacity of EC2 instance (more memory/CPU) or use smaller capacity instances but create more of them when traffic increases. • There are tools they provide to help you calculate optimum configuration

  19. ELB (Load Balancer) • You can upload your SSL certificate for HTTPS connection • If you have an intermediate certificate from SSL provider, open up the file and swap the two certificates around • Make sure you don't use HTTPS between Load Balancer and EC2 instance • ELB will set up a header: • HTTP:X-Forwarded-Proto = https • You can set up apache to detect it and do redirections or do it via PHP code

  20. Route 53 Domain Name Service (DNS) server for use with your custom domain. • You need it to link custom domains to your EC2 instance or Load Balancer (since they have variable IP addresses) • First you create a “Hosted Zone” with your domain

  21. Route 53 • There will be 2 records already (Type NS and SOA) • Go to your domain name registrar (i.e. godaddy) and change your DNS records to point to the 4 addresses under NS • Click “Create Record Set” and register a Type A. • Link it to your EC2 instance or ELB (they'll be on list) • Wait some time and then your domain will link

  22. BONUS Topic: HHVM and Hack http://www.youtube.com/watch?v=p5S1K60mhQU Haiping Zhao, the Senior Server Engineer at Facebook • One of the biggest bottlenecks at FB was the PHP language. • They had 2 choices: • Change to a faster compiled language • OR make PHP faster

  23. HHVM and Hack • Another language wasn't practical because they had thousands of the best PHP programmers working for them and the code base was already millions of lines. • They chose a two-fold strategy • Make PHP faster • As code needed to be updated, change it to C++ (so percentage of overall PHP codebase gets smaller and smaller over time)

  24. HHVM and Hack Why PHP was chosen: • Easy to read/Easy to Learn • Object Orientated • Weakly typed (don't need to worry about var-type) • Operators overloaded ->Convenient • Core PHP library is small (200-500 basic functions) • Easy to Debug → Just refresh browser • Easy to Read/Write/Debug!

  25. HHVM and Hack To achieve these objectives, certain design decisions were made in PHP Language and Zend Engine. PHP is one of the slowest languages (using a framework will slow it down further)

  26. HHVM and Hack • Ordinary when you refer to PHP, you actually mean the Zend Engine which interprets the PHP code line by line. • FB's original solution was PHP->C++ conversion called HipHop • Then they created HHVM which uses same principles as JVM (Just in time compilation) • FB no longer uses Zend Engine. All PHP is run on HHVM which they released publicly for free

  27. HHVM and Hack HHVM is designed to run 100% of PHP without any changes. To date almost all of PHP runs 'out of the box' To date: Laravel and Codeigniter work 100% with no changes. Symfony works 99%. http://hhvm.com/frameworks/ Instead of waiting for PHP 6 to come around, they also created an extension to PHP language called Hack.

  28. HHVM and Hack Hack helps you help the compiler by telling the compiler what the type of the arguments are to a method, determining what type of array you want to use more specifically etc. By giving more hints to the compiler on what you are trying to achieve, the compiler can optimise your code better. Undo's the features of PHP that make it slow FB claims you can get 5-20x speed increase. Average wordpress site can get 9x increase

  29. HHVM and Hack

  30. HHVM and Hack How does this connect to AWS? On the official github page: https://github.com/facebook/hhvm/wiki/Building-and-installing-HHVM-on-Amazon-Linux-2014.03 There are instructions on how to install it onto an EC2 instance (including a t1.micro)

More Related