+ All Categories
Home > Documents > Amazon AWS – brief intro By “PJ” (JP on meetup.com) iOS and PHP developer, and occasional...

Amazon AWS – brief intro By “PJ” (JP on meetup.com) iOS and PHP developer, and occasional...

Date post: 26-Dec-2015
Category:
Upload: rafe-hudson
View: 216 times
Download: 1 times
Share this document with a friend
Popular Tags:
30
Amazon AWS – brief intro By “PJ” (JP on meetup.com) iOS and PHP developer, and occasional lawyer Contact me via: [email protected]
Transcript
Page 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.

Amazon AWS – brief intro

By “PJ” (JP on meetup.com)

iOS and PHP developer, and occasional lawyer

Contact me via: [email protected]

Page 2: 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

•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 BeanstalkHow 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)

Page 3: 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

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

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

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

Static Server for meetup.com

Very real possibility that meetupstatic.com points to S3 address

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

S3 – Create a bucketYou must create a BUCKET (like a drive) to store your files

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

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”

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

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.

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

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

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

S3 – accessing files using PHP SDK

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

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

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

Elastic Beanstalk

Provides PaaS interface (like Google App Engine and Heroku)Connects EC2, RDS, ELB togetherYou don't need to use Elastic Beanstalk but it is

freeYou only pay for the underlying infrastructure that

is used (i.e. EC2 instances)Provides really convenient way to upload your

software

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

Elastic Beanstalk

ELBELBLoad BalancerLoad Balancer

Incoming Traffic EC2EC2

EC2EC2

EC2EC2

EC2EC2

Makes scaling easy

RDSRDS(DB (DB

Server)Server)

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

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 EnvironmentThe website will be X.elasticbeanstalk.comChose option to also make a separate database

server using RDS productChose 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 instanceChose your RDS database type (i.e. mysql) and

root database name and password and size of database

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

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

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

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%)

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

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)

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

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

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

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

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

Route 53Domain 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

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

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

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

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

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

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)

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

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!

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

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)

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

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

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

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.

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

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

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

HHVM and Hack

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

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)


Recommended