AWS Tutorial
AWS Tutorial
Prepared by:
Amir Vahid
Mohsen Amini Salehi
Exercize description
The exercizes in this course built upon a common case study:
RUBiS is an online web store prototype modeled after eBay.com and is used
to evaluate application design patterns and application server’s performance
scalability. It is designed a client that emulates users behavior for various
workload patterns and provides statistics.
The auction site defines 26 interactions that can be performed from the
client’s Web browser. Among the most important ones are browsing items by
category or region, bidding, buying or selling items, leaving comments on
other users. Browsing items also includes consulting the bid history and the
seller’s information. In addition, RUBiS uses a MySQL database that contains
7 tables: users, items, categories, regions, bids, buy_now, and comments.
Over the exercizes we use different entities which their specs
Background
S3 is a paid storage service run by Amazon.
Buckets are similar to directories (folders) in S3.
Files stored in S3 are called “Objects” and the file names called “Keys”.
All objects (files and directories) are stored within buckets.
Create a bucket on S3
Using AWS Management Console:
3. Key in the name (“s3Training”) and the region for new bucket and press
create.
4. Keep the region as its default (US Standard)
5. To set up server access logging for the bucket you can click onSet Up
Logging>
Exercize 2. Uploading files to S3
What should be able to do
Uploading files care called Creating Objects in a bucket.
In this exercise we upload pictures that are needed in our web site to S3.
Uploading files to S3
To carry out this exercize, first download needed files from the following
address:
https://s3.amazonaws.com/S3Training/Archive.zip
Unzip the downloaded file, unzip it and store it in a folder (preferably name it
“pictures”). Then, follow below steps:
1. Click on “Create Folder”
2. Key in the folder name as “pics”.
3. Enter the pics folder by double-clicking on that.
4. Within the pics folder, click on “Upload”.
Note: When you want to upload a file, you can click on “Set Details” to set
further details about that file.
“Use Reduced Redundancy Storage” is suitable for less important
objects and helps in reducing costs.
“Use Server Side Encryption” is suitable for securing objects on the S3.
After uploading the pictures to the S3, you have to make them visible globally
to be able to use in our web site. For that purpose, follow these steps:
1. Go back to the upper layer (pics folder).
2. Right-click and press “Make Public”.
S3 objects can be used in the created web page (in the previous step). For
that purpose, follow below steps:
1. Open the HTML source code of index.html on your local computer
2. In the last lines you can see some lines commented, uncomment
them.
3. Copy pictures’ URL from S3 (as explained above) and replace them
with “FILE NAME” in the html code.
4. Upload the html file.
5. Make it public.
6. You should be able to see the web page with the pictures added.
12. Copy the object path from S3. For example, for 12.jpg we have:
Pics/12.jpg
13. In the html source code of index.html, replace the CDN-based URL of the
image for the FILE NAME.
14. Upload the modified index.html file.
15. Make the file public and copy the address it in the browser.
16. Now the pictures are downloaded both through the S3 and CloudFront.
Lab Session 2. EC2 and Beanstalk Labs
EC2 components
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that enables you
to launch and manage Linux/UNIX and Windows server instances in Amazon's
data centers.
2 From the Amazon EC2 console dashboard, click Launch Instance. And
choose Classic Wizard
3 From Quick Start TAB, choose an AMI, for the Web instance. To make it
3-tier architecture, you will need another instance -from the same or
another AMI- that will serve as the database server.
4 Next, Choose instance type as micro and leave the availability zone as
default.
5 Set instance details as default. Name the web instance as “Web Server”
and the database as “Database Server”
6 In this step you can create new key pair or choose form exiting ones.
Public/private key pairs allow you to securely connect to your instance
after it launches. Name it test and use it for both instances.
7 In this step you create security groups, which act as a firewall and
determine whether a network port is open or blocked.
a. For Web Server instance open port 80 and 22. The source (-s) can
be modified to allow connection only from particular network or IP
for port 22.
b. For Database Server open 6618 for your Web server (set the source
to your Web server IP address) and then port 22 for administrator
access only.
cd /var/www/PHP/
Here you can find all the PHP files of the E-business site, set the “link”
variable in PHPprinter.php to point your database server by following
commands:
nano PHPprinter.php
Then save the file by pressing “Ctrl+o” and then press “Ctrl+x” to exit. Now
you have to be able to browse categories (which are fetched from database) in
web site by trying to following URL:
Type of Scaling
Amazon provides three types of auto scaling as manual scaling, scaling by
schedule, and scaling by policy. Manual auto scaling is simply initiating a new
instance when needed, and it is the most basic one therefore we are not discussing
it here.
Then re-run the EC2.bat file, in order to update your command line environment
with this variable.
2. Terminate Existing Instances
Autoscaling will launch instances as soon as you create an Autoscaling Group.
Therefore, terminate the current instance in order to avoid confusion once
Autoscaling kicks in.
Exercize 3. Link your Domain to your Web application (Utilizing AWS Route
53)
1. Register your domain first, for example visit domain.com, choose your domain name, and
then purchase it for a desired period of time.
2. Create a Hosted Zone:
i. In the Route 53 console, above the left pane, click Create Hosted Zone. In the right pane,
enter a domain name and, optionally, a comment (for more information about a field, see
the tool tip for the field).
ii. Below the right pane, click Create Hosted Zone.
ii. On the Record Sets page, above the left pane, click Create
Record Set.
No additional cost
There is no additional charge for AWS Elastic Beanstalk; you pay only for the underlying AWS
resources that your application consumes. For details about pricing, see the AWS Elastic Beanstalk
service detail page.
View Application
After you create your application, the details and environment for the application appear in the AWS
Management Console. The Application Details pane on the top of the console provides basic overview
information about your application, including events associated with the application and all versions of
the application. The Environment pane below the Application Details pane displays information about
the Amazon EC2 instances that host your application, along with the AWS resources that AWS Elastic
Beanstalk provisions when it launches your environment. While AWS Elastic Beanstalk creates your
AWS resources and launches your application, the environment will be in a Launching state. Status
messages about launch events are displayed on the environment's information bar.
Change Configuration
You can customize your environment to better suit your application. For example, if you have a
compute-intensive application, you can change the type of Amazon EC2 instance that is running your
application. Some configuration changes are simple and happen quickly. Some changes require AWS
Elastic Beanstalk to delete and recreate AWS resources, which can take several minutes. AWS Elastic
Beanstalk will warn you about possible application downtime when changing configuration settings. In
this task, you change the minimum instance settings for your Auto Scaling group from one to two and
then verify that the change occurred. After the new instance gets created, it will become associated
with your load balancer.
1. Click the Actions drop-down menu on the right of the Environment pane, and select Edit/Load
Configuration.
2. Click the Auto Scaling tab in the Edit Configuration dialog box.
3. Change Minimum Instance Count from 1 to 2. This change increases the minimum number of
AutoScaling instances deployed in Amazon EC2.
4. Click Apply Changes. Wait for the environment's status to change from Updating to Ready,
and now you can verify your changes in ELB.
The information shows that two instances are associated with this load balancer, corresponding to the
increase in Auto Scaling instances.
Clean Up
To make sure you are not charged for any services you don't need, you can clean up by deleting any
unwanted applications and environments from AWS Elastic Beanstalk and AWS services. Verify that
you are not using any AWS Elastic Beanstalk resources by reviewing your applications and deleting
those you no longer need.
To completely delete the application
1. Terminate the environment:
a. In the Application Details view, click the Overview tab.
b. Click the Actions button next to the environment you want to delete and click
Terminate this Environment.
The Terminate Environment dialog box appears.
c. Click the Terminate Environment button.
This Lab walks you through creating and configuring your Amazon RDS DB Instance. We would
cover the following subjects:
Create DB Group
Go to http://aws.amazon.com and sign in using your credentials
Choose RDS tab, then from the navigator column at left select ›DB Parameter
Groups
From the Amazon RDS Console Dashboard, Create ›DB Parameter
Groups and select DB family (mysql 5.1, or mysql 5.5), then give it a
name and description and press yes, create
Now it is a time to customize the DM parameters of the created group.
This task sounds to be quite easy, but because the AWS
Management Console does not allow the manipulation of
parameter group values, you have to go the way using the API from
your command line. Let’s do it using the API tools from Amazon.
Launch a DB instance
From the Amazon RDS Console Dashboard, click Launch DB Instance to
start the Launch DB Instance Wizard. The wizard opens on the Engine
Selection page.
Click the Select button next to the MySQL database engine. The wizard
continues to the DB Instance Details page. The first page of the wizard
displays a list of DB Instance Classes in the DB Instance Class drop-down
list. The DB Instance class defines the CPU and memory capacity of your
DB Instance. On the DB Instance Details page, specify your DB Instance
details as shown in the following table, and then click Continue.
The Auto Minor Version Upgrade option enables your DB Instance to receive minor engine version upgrades
automatically when they become available.
Allocated Storage You can specify how much storage in gigabytes you want initially allocated for your DB Instance. For this
example, type 10.
DB Instance Identifier The DB Instance is a name for your DB Instance that is unique for your account in a Region.
Type mydbinstance in the DB Instance Identifier text box.
Master Username Type a name for your master user in the Master Username text box.
You use the master user name to log on to your DB Instance with all database privileges.
Master Password Type a password for your master user in the Master User Password text box.
After you click the Continue button, the Additional Configuration page
opens where you can set the database name, port, DB parameters and
security groups. Set it according to what is shown in the picture below. As
you can see here we set to the DB parameters and security group to the
groups we have created and set up in previous phases.
After you click the Continue button, the Management Options page
appears. The Management Options panel is where you can specify backup
and maintenance options for your DB Instance. As you can see in the table
if you set the back retention period to a positive number the automated
backup will be enabled. And if you set it to 0, the automated backup will
be enabled. Setting the other options allows you to set the daily range
during which automated back and maintenance can happen. Once done
you can continue to REVIEW panel to check your settings and if all the
options are set correctly the DB can be launched by pressing the “launch
DB instance” button.
Click DB Snapshots in the Navigation list on the left side of the window.
Click on the DB Snapshot that you want to restore from in the My DB
Snapshots list.
Click the Restore from DB Snapshot button.
The Restore DB Instance window appears.
Type the name of the restored DB Instance in the DB Instance Identifier text
box, select the instance type and set the port number as appears in the figure
below
Click the Launch DB Instance button.
Connect to DB instance and migrate your database
In order to migrate your in-house databases to RDS, use mysqldump and run it in
background. It is particularly effective for small amounts of data already
stored in MySQL, the simplest way to transfer it to Amazon RDS is to extract
the data with mysqldump and pipe it directly into Amazon RDS. Here is an
example:
If the data stored in your MYSQL database is bigger than a 1 GB, then its best
to migrate using mysqlimport. We'll start by listing the steps in order and
discuss the details of each separately.
o Create flat files containing the data to be loaded
On Unix-like systems (including Linux), use the 'split'
command. For example, the following command splits the
sales.csv file into multiple files of less than 1GB, splitting only
at line breaks (-C 1024m). The new files will be named
sales.part_00, sales.part_01, etc.
Problem
•How can we enable the user to upload the pictures in any name, size, or format?
•The objective is building a solution that abstracts users from detailed
limitations of uploading pictures to the web site.
Steps
1. Pov-ray is already installed on your instance. You can do a test by
entering the following command:
povray/home/ubuntu/povray/povray-
3.6/scenes/advanced/benchmark.ini
+I/home/ubuntu/povray/povray-
3.6/scenes/advanced/landscape.pov +FT +W100 +H50
2. There are two jar files on your EC2 instance. You can find them in
SQSconsumer directory.
You can follow documentation in java source codes from consumer and producer
directories. Here we describe the main parts of producer and consumer code.
In Producer code:
//This class is in charge of downloading objects from S3 bucket to the processing
nodes (EC2 instances) and send a message to SQS
public class Producer {
try {
// Create a queue
"QUEUENAME");
.getQueueUrl();
//we should maintain a sequence number to keep the order of items in SQS or identify the last
element in the queue.
int seqNo = 0;
//##############################
//###############################
objectSummary.getKey()));
copyFile(object.getObjectContent(), objectSummary.getKey());
seqNo++;
//##############################
//###############################
String txtMsg=objectSummary.getKey()+":"+seqNo;
sqs.sendMessage(msg);
seqNo++;
String endMsg="endq"+":"+seqNo;
sqs.sendMessage(new SendMessageRequest(myQueueUrl,endMsg));
//Exception handling
//Exception handling
Consumer Code:
//This class is in charge of reading messages from queue and does the processing.
.getResourceAsStream("AwsCredentials.properties")));
int rcvCounter = 0;
boolean sw = false;
try {
String myQueueUrl =
sqs.getQueueUrl(getQueueUrlRequest).getQueueUrl();
do {
sw = true;
break;
} else {
//If the read message is “endq” but the sequence number is not consistent, it means that there
are still other items in the queue.
continue;
Runtime.getRuntime().exec(cmdString);
rcvCounter++;
System.out.println("Deleting a message.");
sqs.deleteMessage(new
DeleteMessageRequest(myQueueUrl,messageRecieptHandle));
//Checks if the queue end is received (therefore sw=true), then exits the loop.
if (sw == true) {
break;
} while (true);
// sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));
}
Exercize 2. VPC
What should be able to do
Problem
Create a VPN connection to an Amazon EC2 instance.
Steps
1. In the management Console, click on VPC tab.
2. Select “Get started create VPC”.
10. Create a new security group with the rules mentioned in the following
picture:
11. Review the setting and lunch the instance
22. Connection based on HTTPS is created and you are asked for the
credential of the instance (VPN server).
23. VPN server setting