198
Christopher M. Judd in the cloud Thursday, August 29, 13

Java in the (Amazon) Cloud

Embed Size (px)

DESCRIPTION

Wonder what all the Cloud Computing hype is about? Want to know how to deploy a standard Java web application to the cloud and get limitless scalability? Well, this hands on tutorial will answer all your questions and provide confidence by walking you through the process of deploying a sophisticated Java web application to the Amazon Web Service (AWS) Cloud. During this tutorial you will provision clustered servers (EC2), relational database (EC2 and EBS), load balancer (Elastic Load Balancing), content delivery (Cloud Front) and how to monitor your whole infrastructure. Other Amazon Web Services will be demonstrated and discussed as appropriate.

Citation preview

Page 1: Java in the (Amazon) Cloud

Christopher M. Judd

in the cloud

Thursday, August 29, 13

Page 2: Java in the (Amazon) Cloud

Christopher M. JuddCTO and Partner at

leader

Columbus Developer User Group (CIDUG)

Thursday, August 29, 13

Page 3: Java in the (Amazon) Cloud

https://github.com/zendern/nuezThursday, August 29, 13

Page 4: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 5: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 6: Java in the (Amazon) Cloud

What is cloud computing?

How is different from what I am

doing today?

How do I get started?

Will I get a raise?

Thursday, August 29, 13

Page 7: Java in the (Amazon) Cloud

Cloud Computing

Thursday, August 29, 13

Page 9: Java in the (Amazon) Cloud

Software as a service (SaaS) - “on-demand” software

Platform as a service (PaaS) - solution stack

Infrastructure as a service (IaaS) - virtual computing infrastructure

Thursday, August 29, 13

Page 10: Java in the (Amazon) Cloud

PaaS IaaS

AWS Elastic Beanstalk

⬇flexibility⬆⬇complexity⬆⬇cost⬆

Thursday, August 29, 13

Page 11: Java in the (Amazon) Cloud

DevOps

an emerging set of principles, methods and practices for communication, collaboration and integration between software development (application/software engineering) and IT operations (systems administration/

infrastructure) professionals. It has developed in response to the emerging understanding of the interdependence and importance of both the development and operations disciplines in meeting an

organization's goal of rapidly producing software products and services.

Thursday, August 29, 13

Page 12: Java in the (Amazon) Cloud

treat infrastructure like cattle not like pets

Thursday, August 29, 13

Page 13: Java in the (Amazon) Cloud

Current Architecture

Thursday, August 29, 13

Page 14: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 15: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 16: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 17: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 18: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 19: Java in the (Amazon) Cloud

traditional Java architecture

Thursday, August 29, 13

Page 20: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 21: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 22: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 23: Java in the (Amazon) Cloud

AWS architecture

Thursday, August 29, 13

Page 24: Java in the (Amazon) Cloud

AWS architecture

Thursday, August 29, 13

Page 25: Java in the (Amazon) Cloud

Amazon web services architecture

Thursday, August 29, 13

Page 26: Java in the (Amazon) Cloud

AWS Elastic Beanstalk architecture

Thursday, August 29, 13

Page 27: Java in the (Amazon) Cloud

AWS architecture

Thursday, August 29, 13

Page 28: Java in the (Amazon) Cloud

Registration

Thursday, August 29, 13

Page 29: Java in the (Amazon) Cloud

http://aws.amazon.com/

start here

Thursday, August 29, 13

Page 30: Java in the (Amazon) Cloud

need a valid email address

Thursday, August 29, 13

Page 31: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 32: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 33: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 34: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 35: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 36: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 37: Java in the (Amazon) Cloud

AWS Account

admins opsdevelopers

user/group based security

Thursday, August 29, 13

Page 38: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 39: Java in the (Amazon) Cloud

developers

cmj njz jjs cmj0

* all accounts will be removed in a month

563700736850

Thursday, August 29, 13

Page 40: Java in the (Amazon) Cloud

http://escab.elasticbeanstalk.com/registration/

Register for your user account

You AWS Credentials will be emailed to you. If you don’t see it check your spam folder.

Thursday, August 29, 13

Page 41: Java in the (Amazon) Cloud

https://github.com/zendern/escabThursday, August 29, 13

Page 42: Java in the (Amazon) Cloud

https://563700736850.signin.aws.amazon.com/console

initials

codemash

AWS account #

Thursday, August 29, 13

Page 43: Java in the (Amazon) Cloud

https://console.aws.amazon.comThursday, August 29, 13

Page 44: Java in the (Amazon) Cloud

Interfaces

Thursday, August 29, 13

Page 45: Java in the (Amazon) Cloud

Web Console

Thursday, August 29, 13

Page 46: Java in the (Amazon) Cloud

Command-line

Thursday, August 29, 13

Page 47: Java in the (Amazon) Cloud

SDK Language Support

http://aws.amazon.com/tools/Thursday, August 29, 13

Page 48: Java in the (Amazon) Cloud

EC2

Thursday, August 29, 13

Page 49: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 50: Java in the (Amazon) Cloud

A virtual machine (VM) is a software implementation of a machine (i.e. a computer) that executes programs like a physical machine. Virtual machines are separated into two major categories, based on their use and degree of correspondence to any real machine. A system virtual machine provides a complete system platform which supports the execution of a complete operating system (OS). In contrast, a process virtual machine is designed to run a single program, which means that it supports a single process. An essential characteristic of a virtual machine is that the software running inside is limited to the resources and abstractions provided by the virtual machine—it cannot break out of its virtual world.

Thursday, August 29, 13

Page 51: Java in the (Amazon) Cloud

AMIs (Amazon Machine Images)

Thursday, August 29, 13

Page 52: Java in the (Amazon) Cloud

Public AMIs8180 of them and counting

http://aws.amazon.com/amisThursday, August 29, 13

Page 53: Java in the (Amazon) Cloud

That's awesome....

All I have to do is find what I need and off I go. Someone else created it, maintains it.... 

Thursday, August 29, 13

Page 54: Java in the (Amazon) Cloud

But there could be some issues with using these.....

Thursday, August 29, 13

Page 55: Java in the (Amazon) Cloud

Did this guy setup this server?

Thursday, August 29, 13

Page 56: Java in the (Amazon) Cloud

Who knows....

Thursday, August 29, 13

Page 57: Java in the (Amazon) Cloud

Don't be discouraged....

http://cloud.ubuntu.com/ami/ http://fedoraproject.org/wiki/Cloud_images

http://blog.susestudio.com/2011/03/opensuse-114-for-amazon-ec2.html

Thursday, August 29, 13

Page 58: Java in the (Amazon) Cloud

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale computing easier for developers.

• Elastic• Completely Controlled• Flexible• Reliable

Thursday, August 29, 13

Page 59: Java in the (Amazon) Cloud

EC2 Instance Types•Micro•M1 Small•M1 Medium•M1 Large•M1 Extra Large•M3 Extra Large•M3 Double Extra Large•High Memory Extra Large•High Memory Double Extra Large•High Memory Quadruple Extra Large•High CPU Medium•High CPU Extra Large•Cluster Compute Eight Extra Large•Cluster GPU Quadruple Extra Large•High I/O Quadruple Extra Large•High Storage

Thursday, August 29, 13

Page 60: Java in the (Amazon) Cloud

Cost for On Demand

Thursday, August 29, 13

Page 61: Java in the (Amazon) Cloud

Cost for Reserved Instances

Thursday, August 29, 13

Page 62: Java in the (Amazon) Cloud

Bandwidth Pricing

Thursday, August 29, 13

Page 63: Java in the (Amazon) Cloud

EC2with

web console

Thursday, August 29, 13

Page 64: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 65: Java in the (Amazon) Cloud

start here

Thursday, August 29, 13

Page 66: Java in the (Amazon) Cloud

then here or here

Thursday, August 29, 13

Page 67: Java in the (Amazon) Cloud

launch here

Thursday, August 29, 13

Page 68: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 69: Java in the (Amazon) Cloud

search for codemash select JavaWebServer AMI

7.x

Thursday, August 29, 13

Page 70: Java in the (Amazon) Cloud

effects redundancy and scale effects price and performance

effects availability zone

Thursday, August 29, 13

Page 71: Java in the (Amazon) Cloud

nothing to do here

Thursday, August 29, 13

Page 72: Java in the (Amazon) Cloud

nothing to do here

Thursday, August 29, 13

Page 73: Java in the (Amazon) Cloud

name instance with naming convention

Thursday, August 29, 13

Page 74: Java in the (Amazon) Cloud

create or use key pair for remote login

create new key pair name key pair

download key pairand copy it to ~/.ssh

Thursday, August 29, 13

Page 75: Java in the (Amazon) Cloud

ssh rule

allowed ip addresses

Thursday, August 29, 13

Page 76: Java in the (Amazon) Cloud

ssh

open to the worldtomcat

Thursday, August 29, 13

Page 77: Java in the (Amazon) Cloud

Increased Security

Thursday, August 29, 13

Page 78: Java in the (Amazon) Cloud

your doneThursday, August 29, 13

Page 79: Java in the (Amazon) Cloud

ok, almost doneThursday, August 29, 13

Page 80: Java in the (Amazon) Cloud

your new instance

server name

Thursday, August 29, 13

Page 81: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 82: Java in the (Amazon) Cloud

Remote access to your EC2 instance

$ ssh -i ~/.ssh/your-key-pair.pem [email protected]

The authenticity of host 'ec2-23-22-9-39.compute-1.amazonaws.com (50.19.72.29)' can't be established.RSA key fingerprint is 0b:c1:e1:b4:50:ec:cf:e7:a5:cb:20:4f:74:34:c5:29.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'ec2-23-22-9-39.compute-1.amazonaws.com,50.19.72.29' (RSA) to the list of known hosts.

key downloaded earlier login as ec2-user server name

Thursday, August 29, 13

Page 83: Java in the (Amazon) Cloud

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: UNPROTECTED PRIVATE KEY FILE! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0644 for '~/.ssh/your-key-pair.pem' are too open.It is recommended that your private key files are NOT accessible by others.This private key will be ignored.bad permissions: ignore key: ~/.ssh/your-key-pair.pemPermission denied (publickey).

don’t panic$ chmod 400 ~/.ssh/your-key-pair.pem

Thursday, August 29, 13

Page 84: Java in the (Amazon) Cloud

$ssh -i ~/.ssh/your-key-pair.pem [email protected] login: Thu Dec 29 13:47:16 2011 from 70.60.135.250

__| __|_ ) _| ( / Amazon Linux AMI ___|\___|___|

See /usr/share/doc/system-release/ for latest release notes.There are 3 security update(s) out of 4 total update(s) available-bash: EXPORT: command not found[ec2-user@ip-10-245-202-126 ~]$

your in, now you can:install softwarestart services

Thursday, August 29, 13

Page 85: Java in the (Amazon) Cloud

SSHing using Putty

Thursday, August 29, 13

Page 86: Java in the (Amazon) Cloud

Importing the PEM file

Import PEM file for conversion

Thursday, August 29, 13

Page 87: Java in the (Amazon) Cloud

Conversion of Pem to PPK

Save private key (ppk)

Thursday, August 29, 13

Page 88: Java in the (Amazon) Cloud

Setting up Putty to use PPK

1. Navigate to Connection> SSH

> Auth

2. Select ppk file here

Thursday, August 29, 13

Page 89: Java in the (Amazon) Cloud

Log in via PuttyWhen prompted for login enter ec2-user

Thursday, August 29, 13

Page 90: Java in the (Amazon) Cloud

create a new AMI from this

Thursday, August 29, 13

Page 91: Java in the (Amazon) Cloud

Regions and Availability Zones

Thursday, August 29, 13

Page 92: Java in the (Amazon) Cloud

Regions and Availability Zones

US West US East

us-east-1b us-east-1c

us-east-1aus-west-1a

us-west-1b us-west-1c

Thursday, August 29, 13

Page 93: Java in the (Amazon) Cloud

Regions and Availability Zones

N. California N. Virginia

us-east-1b us-east-1c

us-east-1aus-west-1a

us-west-1b us-west-1c

Thursday, August 29, 13

Page 94: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 95: Java in the (Amazon) Cloud

change region here

Half/Half

Thursday, August 29, 13

Page 96: Java in the (Amazon) Cloud

EC2with

Command Line

Thursday, August 29, 13

Page 97: Java in the (Amazon) Cloud

Setup For Console Usage

Thursday, August 29, 13

Page 98: Java in the (Amazon) Cloud

Console Environment Setup

• Download AWS Console API Toolso http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88

• Setup Your Patho export EC2_HOME=<Path to extracted download above>o export PATH=$PATH:$EC2_HOME/bino export EC2_PRIVATE_KEY=<Path to downloaded key pair>o export EC2_CERT=<Path to downloaded X.509 certificate>o export JAVA_HOME=<Path to java install>

Thursday, August 29, 13

Page 99: Java in the (Amazon) Cloud

Console Usage

• ec2-describe-images -o amazon• ec2-add-keypair <key-pair-name>• ec2-add-group <sec-group> -d <description>• ec2-authorize <sec-group> -p 22• ec2-run-instances <ami-id> -k <key-pair-name> -g <sec-group>• ec2-describe-instances• ssh -i <key-pair-pem-file> ec2-user@ec2-xx-xxx-xx-

xx.compute-1.amazonaws.com• ec2-stop-instances <instance-id>• ec2-terminate-instances <instance-id>

Thursday, August 29, 13

Page 100: Java in the (Amazon) Cloud

EC2with

Java SDK

Thursday, August 29, 13

Page 101: Java in the (Amazon) Cloud

//SETUP CREDENTIALSAWSCredentials creds = newPropertiesCredentials(this.getClass().getResourceAsStream("/awsCredentials.properties")); 

//CREATING EC2 CLIENTAmazonEC2 ec2 = new AmazonEC2Client(creds);

Letting AWS know who you areUsing Java SDK

Thursday, August 29, 13

Page 102: Java in the (Amazon) Cloud

Creating a New Key PairUsing Java SDK

CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();

String keyName = "testKeyPair-fromjava";createKeyPairRequest.withKeyName(keyName);

CreateKeyPairResult createKeyPairResult = ec2.createKeyPair(createKeyPairRequest);

KeyPair keyPair = createKeyPairResult.getKeyPair();File pemFile = new File(keyName + ".pem");

BufferedWriter out = new BufferedWriter(new FileWriter(pemFile));out.write(keyPair.getKeyMaterial());out.close();

Thursday, August 29, 13

Page 103: Java in the (Amazon) Cloud

Creating a Security Group Using the Java SDK

CreateSecurityGroupRequest r1 = new CreateSecurityGroupRequest("webserver-group", "Sec Group for My Web Servers");ec2.createSecurityGroup(r1);

AuthorizeSecurityGroupIngressRequest r2 = new AuthorizeSecurityGroupIngressRequest(); r2.setGroupName("webserver-group"); IpPermission permission = new IpPermission(); permission.setIpProtocol("tcp"); permission.setFromPort(80); permission.setToPort(80); List ipRanges = new ArrayList(); 

//use CIDR notation, see http://en.wikipedia.org/wiki/CIDR_notation ipRanges.add("0.0.0.0/0"); permission.setIpRanges(ipRanges); 

List permissions = new ArrayList(); permissions.add(permission); r2.setIpPermissions(permissions);  ec2.authorizeSecurityGroupIngress(r2);

Thursday, August 29, 13

Page 104: Java in the (Amazon) Cloud

Creating the EC2 InstanceUsing the Java SDK

// CREATE EC2 INSTANCESRunInstancesRequest runInstancesRequest = new RunInstancesRequest()    .withInstanceType("micro")    .withImageId("ami-4bb96d22")    .withMinCount(1)    .withMaxCount(1)    .withSecurityGroupIds("webserver-group")    .withKeyName("testKeyPair-fromjava");

RunInstancesResult runInstances = ec2.runInstances(runInstancesRequest);

Thursday, August 29, 13

Page 105: Java in the (Amazon) Cloud

Giving the Instance Metadata

// TAG EC2 INSTANCES WITH USER METADATAList<Instance> instances = runInstances.getReservation().getInstances();for (Instance instance : instances) { CreateTagsRequest createTagsRequest = new CreateTagsRequest(); createTagsRequest.withResources(instance.getInstanceId()) .withTags(new Tag("Name", "MyFirstEC2Instance")); ec2.createTags(createTagsRequest);}

Thursday, August 29, 13

Page 106: Java in the (Amazon) Cloud

Stopping/Terminating EC2 Instance

TerminateInstancesRequest terminateInstanceRequest = new TerminateInstancesRequest().withInstanceIds(instanceIds);ec2.terminateInstances(terminateInstanceRequest);

StopInstancesRequest stopInstanceRequest = new StopInstancesRequest().withInstanceIds(instanceIds);ec2.terminateInstances(stopInstanceRequest);

Thursday, August 29, 13

Page 107: Java in the (Amazon) Cloud

http://puppetlabs.com/http://www.opscode.com/chef/

Infrastructure Automation

AWS CloudFormation

http://aws.amazon.com/cloudformation/

Thursday, August 29, 13

Page 108: Java in the (Amazon) Cloud

Lab 1

1. Start instance of UberConf-2013-JavaWebServer2. Verify Tomcat is running accessible3. ssh to JavaWebServer instance4. Stop JavaWebServer instance5. Restart JavaWebServer instance

Thursday, August 29, 13

Page 109: Java in the (Amazon) Cloud

Storage

Thursday, August 29, 13

Page 110: Java in the (Amazon) Cloud

• Structured Data• Amazon DynamoDB - NoSQL DB• Relational Databases (in EC2 and EBS)• Amazon RDS - Managed databases like mysql• Amazon ElasticCache - in-memory cache• Amazon Redshift - petabyte-scale data warehouse

• Unstructured Data• Amazon EC2 Instance Storage - local filesystem• Amazon EBS Volumes - remote mounted filesystem• Amazon S3 - bucket storage• Amazon Glacier - archiving and backup

Storage Options

Thursday, August 29, 13

Page 111: Java in the (Amazon) Cloud

instance

EBSThursday, August 29, 13

Page 112: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 113: Java in the (Amazon) Cloud

S3 Pricing

Thursday, August 29, 13

Page 114: Java in the (Amazon) Cloud

EBS Pricing

Thursday, August 29, 13

Page 115: Java in the (Amazon) Cloud

Database

Thursday, August 29, 13

Page 116: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 117: Java in the (Amazon) Cloud

launch here

Thursday, August 29, 13

Page 118: Java in the (Amazon) Cloud

search for codemash select MySqlServer AMI

5.5Thursday, August 29, 13

Page 119: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 120: Java in the (Amazon) Cloud

nothing to do here

Thursday, August 29, 13

Page 121: Java in the (Amazon) Cloud

nothing to do here

Thursday, August 29, 13

Page 122: Java in the (Amazon) Cloud

name instance with naming convention

Thursday, August 29, 13

Page 123: Java in the (Amazon) Cloud

select existing key pairs

Thursday, August 29, 13

Page 124: Java in the (Amazon) Cloud

developer’s machine

web application security group

Thursday, August 29, 13

Page 125: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 126: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 127: Java in the (Amazon) Cloud

$ ssh -i ~/.ssh/your-key-pair.pem [email protected]

$ mysql -u codemash -pcodemash -e ‘create database nuez’

Thursday, August 29, 13

Page 128: Java in the (Amazon) Cloud

$ mysql -h ec2-54-243-16-144.compute-1.amazonaws.com -u codemash -p nuez

Thursday, August 29, 13

Page 129: Java in the (Amazon) Cloud

user = codemashpassword = codemash

Thursday, August 29, 13

Page 130: Java in the (Amazon) Cloud

// environment specific settingsenvironments { development { dataSource { dbCreate = "update" url = "jdbc:h2:mem:devDb;MVCC=TRUE" } } test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb;MVCC=TRUE" } } production { dataSource { driverClassName = "com.mysql.jdbc.Driver" dialect = "org.hibernate.dialect.MySQL5Dialect" username = "codemash" password = "codemash" dbCreate = "update" url = "jdbc:mysql://ec2-184-72-144-98-compute-1.amazonaws.com:3306/nuez" pooled = true properties { maxActive = -1 minEvictableIdleTimeMillis = 1800000 timeBetweenEvictionRunsMillis = 1800000 numTestsPerEvictionRun = 3 testOnBorrow = true testWhileIdle = true testOnReturn = true validationQuery = "SELECT 1" } } }}

mysql instance urlusername/password

grails-app/conf/DataSource.groovyThursday, August 29, 13

Page 131: Java in the (Amazon) Cloud

grails war

Thursday, August 29, 13

Page 132: Java in the (Amazon) Cloud

$ scp -i ~/.ssh/your-key-pair.pem target/nuez-0.1.war ec2-user@ ec2-23-22-9-39.compute-1.amazonaws.com:/usr/share/tomcat7/webapps/nuez.war

nuez-0.1.war 100% 27MB 666.3KB/s 00:42

Secure Copy War

Thursday, August 29, 13

Page 133: Java in the (Amazon) Cloud

SCP using Windows

Enter ec2-user here

Select you ppkfile here

Enter machine name here

Thursday, August 29, 13

Page 134: Java in the (Amazon) Cloud

Lab 2

1. Start instance of UberConf-2013-MySqlServer2. Connect with mysql tool or ssh to instance3. Create nuez database (if not created already)4. Change nuez application database string5. Deploy nuez application6. Test nuez application

Thursday, August 29, 13

Page 135: Java in the (Amazon) Cloud

Load Balancing

Thursday, August 29, 13

Page 136: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 137: Java in the (Amazon) Cloud

Launch

Launch Similar EC2 Instance

Thursday, August 29, 13

Page 138: Java in the (Amazon) Cloud

Launch

Thursday, August 29, 13

Page 139: Java in the (Amazon) Cloud

Load Balancing Instances

Thursday, August 29, 13

Page 140: Java in the (Amazon) Cloud

Configure Health Check

Thursday, August 29, 13

Page 141: Java in the (Amazon) Cloud

Select EC2 Instances

Thursday, August 29, 13

Page 142: Java in the (Amazon) Cloud

Review

Thursday, August 29, 13

Page 143: Java in the (Amazon) Cloud

Almost done

Thursday, August 29, 13

Page 144: Java in the (Amazon) Cloud

Here is the base urlto access the load

balancer

Getting url to load balancer

Thursday, August 29, 13

Page 145: Java in the (Amazon) Cloud

Lab 3

1. Create/start another instance of UberConf-2013-JavaWebServer

2. Create a new load balancer3. Add both UberConf-2013-JavaWebServer EC2 instances

to load balancer

Thursday, August 29, 13

Page 146: Java in the (Amazon) Cloud

CDN

Thursday, August 29, 13

Page 147: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 148: Java in the (Amazon) Cloud

CloudFront Pricing

Thursday, August 29, 13

Page 149: Java in the (Amazon) Cloud

Start by creating a bucket

Setting up S3 with CloudFront

Thursday, August 29, 13

Page 150: Java in the (Amazon) Cloud

Logging can also be enabledto tell you more about

your S3 usage

Click here to name andfinish creating your

bucket

Name S3 Bucket

Thursday, August 29, 13

Page 151: Java in the (Amazon) Cloud

Create S3 directory structure

Click here to create a newfolder inside your bucket

After clicking you will be prompted to enter the name

here

Thursday, August 29, 13

Page 152: Java in the (Amazon) Cloud

Create this structure using the same names

Create S3 directory structure (continued)

Create this structure using the same names

Thursday, August 29, 13

Page 153: Java in the (Amazon) Cloud

Uploading Static Content

Upload content destination folder

Thursday, August 29, 13

Page 154: Java in the (Amazon) Cloud

Click here to add files (Multi file selection is possible when browse window opens)

Uploading (continued)

Thursday, August 29, 13

Page 155: Java in the (Amazon) Cloud

Select corresponding static files located in the webapp on your machine to be uploaded

into S3

Uploading (continued)

Thursday, August 29, 13

Page 156: Java in the (Amazon) Cloud

Finish by pressing “Start Upload”

Uploading(Almost done)

Thursday, August 29, 13

Page 157: Java in the (Amazon) Cloud

Make All S3 Files Public

Click here to make all files under this directory available

to the world

Thursday, August 29, 13

Page 158: Java in the (Amazon) Cloud

Creating a new Cloudfront

Start by clicking hereor here

Thursday, August 29, 13

Page 159: Java in the (Amazon) Cloud

Selecting CDN Type(download vs. streaming)

Thursday, August 29, 13

Page 160: Java in the (Amazon) Cloud

Setting up S3 as Origin

Thursday, August 29, 13

Page 161: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 162: Java in the (Amazon) Cloud

<link rel="shortcut icon" href="${grailsApplication.config.cloudfront.cdn.url}${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon">

Grails Resource Change to Support CDN url

Thursday, August 29, 13

Page 163: Java in the (Amazon) Cloud

environments { development { grails.logging.jul.usebridge = true cloudfront.cdn.url = "" } production { grails.logging.jul.usebridge = false cloudfront.cdn.url = "http://your.cloudfront.net" }}

Configure Web App

Config.groovy

Thursday, August 29, 13

Page 164: Java in the (Amazon) Cloud

Lab 4

1. Create new S3 bucket2. Create directory structure in S33. Upload all static content to S3 in the appropriate

directories4. Create new CloudFront distribution5. Update nuez to use CloudFront distribution url 6. Redeploy nuez web app7. Test

Thursday, August 29, 13

Page 165: Java in the (Amazon) Cloud

Elastic Beanstalk

Thursday, August 29, 13

Page 166: Java in the (Amazon) Cloud

Elastic Beanstalk

Select you platform

Thursday, August 29, 13

Page 167: Java in the (Amazon) Cloud

Elastic Beanstalk (Default application)

Thursday, August 29, 13

Page 168: Java in the (Amazon) Cloud

Elastic Beanstalk (Default application)

Thursday, August 29, 13

Page 169: Java in the (Amazon) Cloud

Creating your own application

Start here

Thursday, August 29, 13

Page 170: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 171: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 172: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 173: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 174: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 175: Java in the (Amazon) Cloud

Use these fields to construct connection string for application

Thursday, August 29, 13

Page 176: Java in the (Amazon) Cloud

Update Nuez with RDS Connection// environment specific settingsenvironments { development { dataSource { dbCreate = "update" url = "jdbc:h2:mem:devDb;MVCC=TRUE" } } test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb;MVCC=TRUE" } } production { dataSource { driverClassName = "com.mysql.jdbc.Driver" dialect = "org.hibernate.dialect.MySQL5Dialect" username = "codemash" password = "codemash" dbCreate = "update" url = "jdbc:mysql://aa1w2u6dik6dppm.cdrw92njsm5b.us-west-1.rds.amazonaws.com:3306/ebdb" pooled = true properties { maxActive = -1 minEvictableIdleTimeMillis = 1800000 timeBetweenEvictionRunsMillis = 1800000 numTestsPerEvictionRun = 3 testOnBorrow = true testWhileIdle = true testOnReturn = true validationQuery = "SELECT 1" } } }}

rds url

Thursday, August 29, 13

Page 177: Java in the (Amazon) Cloud

Deploy the latest version of nuez

Thursday, August 29, 13

Page 178: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 179: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 180: Java in the (Amazon) Cloud

Start here to modify server configurations

Thursday, August 29, 13

Page 181: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 182: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 183: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 184: Java in the (Amazon) Cloud

Pricing

Thursday, August 29, 13

Page 185: Java in the (Amazon) Cloud

pay as you use

Thursday, August 29, 13

Page 186: Java in the (Amazon) Cloud

use small EC2 instance for one hour and pay $0.065

Thursday, August 29, 13

Page 187: Java in the (Amazon) Cloud

On-Demand - pay by hour no long-term commitmentReserved - one-time payment and discounted hourly rateSpot - bid for unused capacity

Example:

* small instance for one year

On-Demand - $569.40 ($0.065/hr) Light Reserved - $410.64 ($0.039/hr + $69)Medium Reserved - $370.24 ($0.024/hr + $160)Heavy Reserved - $335.16 ($0.016/hr + $195)

Thursday, August 29, 13

Page 188: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 189: Java in the (Amazon) Cloud

http://aws.amazon.com/calculatorThursday, August 29, 13

Page 190: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 191: Java in the (Amazon) Cloud

Resources

Thursday, August 29, 13

Page 192: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 193: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 194: Java in the (Amazon) Cloud

http://aws.amazon.com/architecture/

Thursday, August 29, 13

Page 195: Java in the (Amazon) Cloud

http://aws.amazon.com/architecture/

Thursday, August 29, 13

Page 196: Java in the (Amazon) Cloud

Thursday, August 29, 13

Page 197: Java in the (Amazon) Cloud

http://www.infoq.com/presentations/Netflix-in-the-CloudThursday, August 29, 13

Page 198: Java in the (Amazon) Cloud

CTO and Partneremail: [email protected]: www.juddsolutions.comblog: juddsolutions.blogspot.comtwitter: javajudd

Christopher M. Judd

Thursday, August 29, 13