Building Applications in the CloudBy David Peake
Combine Oracle Application Express and Amazon EC2.
With tightening budgets, IT departments are looking to reduce startup costs for new departmental and other application development projects. One option is to use the Amazon Elastic Compute Cloud (EC2) for developing and deploying Oracle Database and Oracle Application Express applications. Oracle Application Express is browser-based, so you need only provide the URL for the cloud environment to your developers and end users. In addition, the multitenant capabilities of Oracle Database and Oracle Application Express enable multiple development teams and their associated applications to coexist within a single database instance on Amazon EC2.
This column describes the process of creating an Oracle Application Express instance on Amazon EC2. The cost of using Amazon EC2 services for the hour or so needed to work through this setup is about US$1. Note that Amazon EC2 offers several sizing options, with price points that vary by size and resource consumption; see Amazon Web Services (aws.amazon.com) for more information.
Using the setup in this column, you can completely control service utilization, paying only for what you use and taking the Oracle Application Express service offline when it’s not needed.
The licenses associated with Oracle’s Amazon Machine Images (AMIs), available at Amazon Web Services, are for development purposes. (Be sure to check with your Oracle sales representative for the details of your specific licensed privileges before deploying any application into production. The steps detailed in this column are for setting up the Oracle Database 11g AMI.)
Prerequisites and Preliminary Setup
The first step in establishing your cloud environment is to create an Amazon Web Services account and then sign up for these services:
Next, obtain and configure the following client software packages:
Also, download Oracle Application Express 3.2 (oracle.com/products/database/application_express/download.html) to a location on your local machine. After creating your Oracle Database instance, you’ll use this file to upgrade Oracle Application Express.
Creating the Oracle Database Instance
After you’ve signed up for the Amazon services, installed the required software on your local machine, set up the prerequisite KeyPair, and addressed the requirements for using Elasticfox, log in to Amazon Web Services and select the AMI to use as the basis for your Oracle Amazon EC2 instance:
1. From your local machine, launch the Firefox browser.
2. From the Firefox Tools menu, select Elasticfox .
3. Log in to AWS with your credentials. (See the Elastifox Getting Started Guide if you need more information.)
4. Click the Images tab to display the list of available AMIs.
5. Enter oracle into the search field (adjacent to the AMIs list) to filter the list to Oracle AMIs only.
6. Click the ami-cecb2fa7 image from the list to select the 32-bit Oracle Database 11g Enterprise Edition AMI.
7. With the image name selected, right-click and select Launch instance(s) of this AMI .
8. Select the appropriate size for the EC2 Instance Type , based on your initial requirements. (Once the instance is fully configured, you can easily transition from one instance type to another as your requirements change.)
9. Select your KeyPair from the list.
10. Click the Launch button.
In a few minutes, your Oracle Amazon EC2 instance is up and running. The instance’s public domain name service (DNS) name and other properties appear in the list on the Instances tab.
Review the Elasticfox Getting Started Guide for more information on the Amazon EC2 Web service.
To configure your Oracle on Amazon EC2 instance for Oracle Application Express, add permissions to the default security group by following these steps:
1. From the Elasticfox interface, click the Security Groups tab.
2. In the left pane (labeled Your Groups), click the default group in the list to select it and see the permissions for the group in the right pane.
3. Click the green check mark above the right pane (Group Permissions) to open the Grant New Permission dialog box, select SSH from the list, and enter 22 in the port field. Limit access to your machine by clicking the Get My Host Address button in the Host/Network Details section of the dialog box and then clicking the Add button.
4. Click the grant permission check mark again, and allow anyone to access port 8080. For Host/Network Details , enter Network 0.0.0.0/0 .
You use PuTTY to log in to Amazon EC2 and create a new database instance. Before you can use PuTTY, however, you must first use PuTTYgen to convert the .pem KeyPair file to a .ppk file:
1. Start PuTTYgen on the command line of your local machine.
2. Click Load and then Browse to find the .pem KeyPair file created with Elasticfox.
3. Click Save Private to save the .pem file as a .ppk file.
With the KeyPair file converted, use PuTTY to connect to your Amazon EC2 instance, create an Oracle Database instance, and configure the new instance:
1. Start PuTTY.
2. For the host name, enter the Public DNS name (available on the Instances tab). Enter 22 for Port and SSH for Connection Type . If you are working from behind a firewall, you must enter proxy server settings in the Category -> Connection -> Proxy properties section of the PuTTY configuration.
3. Specify the KeyPair to use in the Category -> Connection -> SSH -> Auth section of the PuTTY configuration, by browsing to the location of the KeyPair (.ppk) file you saved with PuTTYgen.
4. Click Open to connect to your Amazon EC2 instance. Accept the server’s certificate when prompted.
5. When the PuTTY screen appears, log in as root. The KeyPair authenticates your session and initiates an installation script that presents license information.
6. Review the license agreements, and if you accept the terms, enter y.
7. Create a password for the Oracle user account when prompted.
8. At the prompt to create a new database, enter y .
9. Select defaults for disk devices to store datafiles, redo logs, and flash recovery area files.
10. At the prompt confirming details, enter y to continue.
11. Create your Oracle system ID (SID) and passwords for SYS, SYSTEM, DBSNMP, SYSMAN, and APEX ADMIN.
The new database instance is created and configured automatically.
Upgrading the Oracle Application Express Installation
Although Oracle Database 11g and Oracle Application Express 3.0.1 are now fully operational on your Oracle-on-Amazon-EC2 instance, to use the latest Oracle Application Express features, upgrade the system to the latest version of Oracle Application Express (Oracle Application Express 3.2), using the zip file you downloaded earlier.
To upgrade Oracle Application Express, do the following:
1. Start your FTP client, such as WinSCP, and connect to your Oracle-on-Amazon-EC2 instance.
2. Copy the apex_3.2.zip file from your local workstation to the /home/oracle directory of your Oracle-on-Amazon-EC2 instance.
3. From your PuTTY terminal, log in to the instance, and unzip the Oracle Application Express 3.2 zip file:
su - oracle unzip apex_3.2.zip
4. Install Oracle Application Express 3.2, upgrade the images, and set the ADMIN password:
cd apex sqlplus / as sysdba SQL>@apexins SYSAUX SYSAUX TEMP /i/ su - oracle sqlplus / as sysdba SQL>@apxldimg /home/oracle SQL>@apxchpwd
Enter a new password for the Oracle Application Express ADMIN account when prompted.
5. Using Firefox, navigate to the Oracle Application Express instance on Amazon EC2:
http://<Public DNS Name>:8080/apex/apex_admin
6. Using the Oracle Application Express ADMIN account and the password you entered above, log in to Oracle Application Express.
7. From the Oracle Application Express Administration Services page, create workspaces ( Manage Workspaces -> Create Workspace ), create developer accounts, and set up the other details for your departments as necessary.
Provide the URL, user account names, and temporary passwords to your user community to enable developers to log in to their workspaces by using Firefox or Internet Explorer and working as they normally would on any Oracle Application Express instance.
Establishing Amazon EBS
At this point, all datafiles that constitute the Oracle Application Express instance reside in the same environment as the Amazon EC2 instance. If you were to shut down the instance, however, any data would be gone.
Amazon’s EBS service enables you to create persistent volumes to use with your Amazon EC2 instance. After configuring an Amazon EBS volume, you can associate it with your Amazon EC2 instance, by first shutting down the Amazon EC2 instance, changing the Amazon EC2 instance type if necessary, and then mounting your Amazon EBS volume when starting up the new instance.
To create your EBS volume, follow these steps:
1. From the Elasticfox interface, select the Volumes and Snapshots tab.
2. Click the Create new volume icon.
3. Enter 10 for the size, in gigabytes, of the volume. For the availability zone, select the same zone as that of your Amazon EC2 instance.
4. Click the Instances tab, right-click your Amazon EC2 instance, select Attach an EBS Volume , and name the device—for example, /dev/sdf1.
To format the volume, return to the PuTTY terminal session and do the following:
1. As the root user, format and mount the Amazon EBS volume and specify the mount point. For example, if the Amazon EBS device name is /dev/sdf1, use this code:
mkfs.ext3 /dev/sdf1 mount /dev/sdf1 /mnt df -m
Make note of all file systems and mount points. The last entry should be something similar to /u02.
2. Shut down the instance, and then copy the files to the new mount point on the Amazon EBS volume:
su - oracle sqlplus / as sysdba SQL> shutdown immediate SQL> exit cp -r /u02/* /mnt/ $ exit
3. Using the information you obtained by running df -m, specify the current mount point for /u02 (such as /dev/sda2), unmount the volumes, remount the Amazon EBS volume, and start the database. For example, if the Amazon EC2 device name is /dev/sda2 and the Amazon EBS device name is /dev/sdf1, the code is
umount /dev/sda2 umount /dev/sdf1 mount /dev/sdf1 /mnt su - oracle sqlplus / as sysdba SQL> startup
With your Amazon Web Services environment fully configured, you can start rapidly creating applications with Oracle Application Express. As demand rises or falls, you can easily reconfigure your environment to adjust to changing requirements by changing your level of service. For example, you can take the entire stack offline during periods when the applications are not needed at all, and the cost meter will stop.
You can also migrate applications developed on Amazon EC2 onto your internal systems. After ensuring that the correct version of Oracle Application Express is installed on the target server, export the Oracle Application Express application, database schema, and data from Amazon EC2 and then import them onto the target server.
David Peake (email@example.com) is a principal product manager in Oracle’s Server Technologies division. He has been with Oracle since 1993.