From simple to full featured cloud capacity
Cloud technologies and services increase every day. Global players like Amazon put continuously new features to their cloud and products to provide sufficiently functionality of actually web development activities and requirements.
Services for us
In fact, Amazon starts with the S3 (Simple Storages Service) to provide cloud storage space since 2006 and only a few months later EC2 (Elastic Compute Cloud) was launched a service to provide computing power to manage capacity as many as we need over time. Now, RDS (Relational Database Service) is available to get elastic database power as much as we need to cover all components that we require to implement the whole stack of current web applications.
Use that services to transform the development and of course every application in a liquid and full dynamic status. Every service increase productivity and can be used to cover architecture requirements in sufficient way. That means, use every service as long as we need and allocate capacity as many as we need in the finest way up to 100% not more, not less to reduce resources and costs.
Swim a little bit around
Ok let us start to introduce each important service below to get more details and show examples what we have to do to use these services. Amazon provides a SDK especially for PHP developers to connect each service. You can download the SDK under the following URL:
To start, download and install the SDK to your destination directory in your application root folder. Before we can start edit the configuration file and change the privacy settings with your AWS (Amazon Web Services) credentials (see Listing 1). To get credentials please create an AWS account on:
http://aws.amazon.com/de/ and follow the instructions.
Store data in S3 and handle it similar to our local storages
S3 is the storages service from Amazon where we can store (Create), retrieve (Read), overwrite (Update) and remove (Delete) data. The logical structure based on buckets that contains items like files e.g. images, videos or documents or any data that we want to store. Buckets must have a unique developer-assigned key across the account each item can be contain 1 byte up to 5 terabytes.
Create our bucket
First, to store our objects we create a bucket with the method create_bucket. All what we have to do is specify a name of the bucket “testbucket” and the region where we want to create it. In our case the region is “EU_E1” (European 1- Region). Additionally, a simple “if check” covers the return value whether the call was correct.
Store our private data
In the next step, we put files to the bucket and store some data to the cloud. Simply, call the create_object method to handle our request.
Listing 3 shows the PHP snippet to create a test file. Call the method with the bucket name “testbucket”, name of the file “testfile.txt” and some additional parameters in our case “body”, “acl” and “contentType” to specify the characteristic of our data.
Get data from the cloud storage
Now we want to get back our stored data. To finalize that request we have to use the method get_object.
Listing 4 visualizes that request and shows the method call with the parameters “testbucket” that is our bucket name and the name (key) of the file “testfile.txt” where our data will be stored.
Execute our get_object.php file and receive the entire string from the cloud storage for further use.
Listing 5 covers our example and echoed the string that we have inserted a few minutes before.
To see it is very simple to communicate to our cloud storage with the SDK and execute the proper methods. If you do not know the right method take a look in the library service file where every single method is described well that enclose every required parameter and excepted return values.
Allocate computing resources as much as we need
EC2 is the next create cloud services that we can use to allocate computing resources for our web environment. Through defined methods from the SDK and the proper service file you can easily start an AMI (Amazon Machine Image) with an operating system that match our requirements. There are images from the market leaders like Linux and Windows systems and you can upload an own image as well whether you need a self defined system e.g. pre-installed web, db or chat server. Please go to the Amazon website:
to see which kind of images are available that fits your requirements. After we have chosen a suitable images we can start it with a method call from the SDK similar create a bucket in S3.
Listing 6 shows that method call run_instances with the parameter “ami-48aa4921” with specifies the machine images that will be loaded and some optional parameters in that case the type of the underlying hardware configuration which is specified by “m1.micro” instance – currently the smallest type with 2 processor kernels (CPUs) – and round about 613MB RAM. Check the response value with the method isOk. If everything is fine we can connect our recently started machine through a secure shell.
Listing 7 visualize a connection to the virtual machine that we have started. We need only our private key that you can download from the AWS account and the hostname of the machine that you can find on the EC2 overview simply go to the AWS website:
After the login (see Listing 8) we see our secure shell of the machine where we can input commands like on our self administrated local systems.
Similar S3, EC2 is also pretty easy to use with some SDK commands like run_instances that helps us to integrate this service into our web application. You need only a valid AWS account (key credentials) to access the service, a machine image like “ami-48aa4921” and a proper instance type e.g. “m1.micro” with sufficient processor and memory power.
RDS a service to handle relational database capacity
The final service that we want to cover is the RDS service the third part to complete our web environment stack. It is also pretty easy to use it with the SDK. Call only a single method to start a new RDS instance and connect to the machine.
See Listing 9 to show an example how to create a database instance. Execute simple the method create_db_instance with the parameter ‘testinstance’ the name of the instance, “5” specifies the size of the db storages in GB, “db.m1.small” clarifies the size of the underlying instance type (varies in processor and memory power), “MySQL” the type of the database system, “testuser” a user name and “testpassword” the password to connect the database. Check also with the isOk method the response value to guarantee the availability of the system.
Now we can connect to our new instantiated database through a secure shell. Input only the following known MySQL client command to connect. Specify the user name, password and the database host (see Listing 10).
After we have connected to the database server we will see the start screen where we can input commands (see Listing 11).
Check out which tables are available and execute the show databases command. Additionally, show all tables in the MySQL database with the show tables command (see Listing 12).
What happens at the cloud front?
In this blog post we have cover common cloud services from the Amazon service. S3, EC2 and the RDS are services to extend and of course to replace current development architectures where normally dedicated machines and systems work. With the SDK it is very simple to connect all the services, request commands and response values e.g. S3 items. These proposed services cover a small overview about available services. There are much more excellent functionalities we can use to integrate.
CloudWatch and ELB (Elastic Load Balancer) combined work as a service to measure system values e.g. processor load, RAM utilization and control capacity. Start more or stop EC2 machines to balance the current load up to 100%.
SimpleDB is an additional database service that based on a key value store without any relation between items unlike relational database systems. Handle data in domains similar buckets in S3 and retrieve values with proper SQL statements.
Last but not least, SQS (Simple Queue Service) integrate a SOA service. Loosely coupled items communicate through defined interfaces. Add values to a queue at one application point and retrieve items on another. Works asynchronous and can be used to handle jobs that converts large data like image or video rendering. Thank you for your attention to read until the end ;-) if you have any comments please add your notes and ideas after that post.