Top Banner
Deploying, Scaling, and Running Grails on AWS and VPC Learn the ropes of networking to maximize your potential Created by / Ryan Vanderwerf @RyanVanderwerf
53

Deploying, Scaling, and Running Grails on AWS and VPC

May 17, 2015

Download

Technology

GR8Conf

This talk will cover how to get your application running on AWS VPC and related services. We will go over some related services and their current state like RDS, autoscaling, s3, cloudfront, s3fs, ebs, elastic beanstalk, etc and how your Grails application can benefit from using these. The networking can also be confusing with your application so we'll cover the basics here as well. I will share lots of random nuggets of information that I have learned the hard and and recommended practices of configuration of your VPC as well.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deploying, Scaling, and Running Grails on AWS and VPC

Deploying, Scaling, andRunning Grails on AWS and VPCLearn the ropes of networking to maximize

your potential

Created by / Ryan Vanderwerf @RyanVanderwerf

Page 2: Deploying, Scaling, and Running Grails on AWS and VPC

About MeLearn the ropes of networking to maximize

your potentialChief Architect @ ReachForceCo-Chair Austin Groovy and Grails User GroupHelp maintain Grails Quartz pluginMaintain GVPS Plugin (Grails Video Pseudo Streamer)Maintain Struts-1 PluginSubmit pull requests for others when I can!

Page 3: Deploying, Scaling, and Running Grails on AWS and VPC

What We Will CoverVPCS3ElasticWolfsshoogr and gramazonGrails PluginsElastic Load BalancersAutoscalingOthers misc tips

Page 4: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Virtual Private CloudRoutingNATACL FirewallSuggested SubnetsSecurity GroupsDHCP TipsOthers misc tips

Page 5: Deploying, Scaling, and Running Grails on AWS and VPC

VPC OverviewNow required on new AWS accountsVery different that EC2 'Classic' which has no private network layerCosts nothing extra - you have nothing to lose

Page 6: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 7: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 8: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnetsadding a 3rd subnet - this gives a helping

handauto-scaling instances can access internet through NATWeb Servers, Web facing apps can live behind ELB yet be able to runOS updatesS3 Buckets accessiblecan access your secure subnet as well

Page 9: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 10: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 11: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 12: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/Subnets

Page 13: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/SubnetsSecurity ACLs

ACLs like a full firewall - unlike groupsProtect subnets instead of EC2 instancesProcessed in order of rule #ACLs are stateless - responses to inbound bound by outbound rulesTo accommodate various clients and OSs open ephemeral ports 1024-65535 then block malicous ports

Page 14: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/SubnetsSecurity Groups

VPC Security Groups are different than EC2 Groups - use different anddescriptive names if both usedYou can use a security group ID (starting with sgXXXXX) in most placeswhere IPs can be enteredProcessed in order of rule #ACLs are stateless - responses to inbound bound by outbound rulesTo accommodate various clients and OSs open ephemeral ports 1024-65535 then block malicous ports

Page 15: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Routing/SubnetsDHCP Options

Determine What DNS DHCP clients useCan do things like set default domain, whether to use internal orexternal DNS for your VPCFrom Web UI, assign only 1 option set at a timeUsing amazon provided DNS, using naming scheme of 10.0.1.x,default domain ec2.internalCan assign your own DNS server names, or even Netbios nameservers or NTP serversOptions are semicolor delimited name value pairs, i.e. 'domain-name=something.com; domain-name-severs=AmazonProvidedDNSs

Page 16: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - IAM RolesDon't use root account anymore. Traditional security page is retiredSet up your IAM roles for each user and use designated login url theygive youUse resource level security with IAM to tier access toinstances/resources

Page 17: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Misc EC2 TipsReboot != Reboot be carefulRebooting a machine from console will keep instance in place andephemeral storage(OS reboot faster)If you issue an 'stop' command you machine will move and loseephemeral state

Page 18: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Misc EC2 TipsVPNUse OpenVPN instead of metered AWS VPN - it runs fine on a tinyinstance- save $$Use OpenVPN client to leave remote servers connected to VPC - itauto-reconnects

Page 19: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Misc EC2 TipsLoad Balancer60s timeout on idle max - can file ticket for extension to 15+ minutesUse Haproxy for anything very advanced, can accommodate manyoptions

Page 20: Deploying, Scaling, and Running Grails on AWS and VPC

VPC - Misc EC2 TipsEBS Based InstancesUse EBS backed instances for anything not build for cloudIf you can build server on the fly with Chef/Puppet like tools, go forephemeral basedEBS backed instances have no swap by default - be sure to specifyephemeral disks on launch, use as swapEBS backed instances have no ephemeral disks on by default be sureto use them on launch of instance and AMIs

Page 21: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageLimitationsCommon toolsRegions with different functionalityGlacierGrails S3 Plugin

Page 22: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageLimitations - Eventual ConsistencyThis means after write/update it will EVENTUALLY be consistentMake your app retry on read fail - it might not be synced yetDifferent regions have different consistency rulesUS-West and EU Buckets have read after write consistency - but notupdate or delete (and cost more)US-East is so large it cannot handle any kind of consistency afterwrite/update/delete - except patience!

Page 23: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageLimitations - large filesFiles over 5GB supported, but most tools don't handle properlyS3 Tools must support mime/multiparts3cmd(Linux) / CyberDuck 4(Mac/Win32) / S3 Browser(Win32) /Cloudberry Explorer(PRO Win32) / Bucket ExplorerFile > 5GB files work with these tools, it is EXTREMELY slow

Page 24: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageToolss3fs - mount as filesystem - but >5GB files broken, beware ofconsistency!Make sure FUSE is in kernels3cmd is best free command line toolsBucket Explorer & CloudBerry Backup are good solid windows clientsthat parallelize multi-part uploads to ease the pains3 Browser is ok free toolFor install on Ubuntu: http://zentraal.com/docs/installing-s3fs-on-ubuntu/

Page 25: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageDifferent Function Between DifferentRegionsUS-East-1 Cheapest for full redundancy otherwise to save $ you canuse RRS (Or Glacier)US-West and EU Buckets have read after write consistency - but notupdate or delete (and cost more)US-East is so large it cannot handle any kind of consistency afterwrite/update/delete - except patience!Barring these limitations (and budget!), use the region closed to yourVPC instances and regions

Page 26: Deploying, Scaling, and Running Grails on AWS and VPC

S3 StorageGrails S3 Plugin

Looks unmaintained, but still works fine on latest Grails versions (noJIRA bugs pending!)Delete Buckets (See )Uploads and catalogs assets (will use bucket name you give as basefor its bucket name)Names files inside bucket with UUIDs to avoid collisionsCan give each asset a bucket and key pair or globalDemo - s3-demo project

org.grails.s3.BucketService

Page 27: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails PluginsGrails AWS PluginAWS SDK PluginDynamoDB GORM Plugin - not coveredAmazon Flexible Payments - not coveredSimpleDB GORM Plugin - not converedCDN Asset Pipeline plugin - not covered

Page 28: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

Actual Groovy/Grails Code to Manage S3storage and SES Service (vs Java wrapper)

Page 29: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

Has handy Gant scripts installed - used forSES stats

Aws-Ses-Get-Send-QuotaAws-Sws-Get-Send-StatisticsAws-Ses-List-Verified-EmailsAws-Ses-Send-Ping-MailAws-Ses-Verify-Email

Page 30: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

Aws-Ses-Get-Send-QuotaGets your current Quota for Simple Email ServiceShows email limit per day, per second, # of emailsOutput looks like this:[AWS SES] The maximum number of emails the user is allowed tosend in a 24-hour interval: 10000.0[AWS SES] The maximum number of emails the user is allowed tosend per second: 5.0 [AWS SES] The number of emails sent during the previous 24 hours:15.0

Page 31: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

Aws-Sws-Get-Send-StatisticsGets your email sending statisticsThe output is a list of items, for the last two weeks of sending activity.Example output:[AWS SES] ------------------------------------------------------------------------------- [AWS SES] | time range | attemps | rejects (SES) | complaints(recipient) | bounces | [AWS SES] |-------------------------------------------------------------------------------| [AWS SES] | 2013/06/26 22:42 | 1 | 0 | 0 | 0 |

Page 32: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

aws-ses-list-verified-emailsShows a list of all verified emails withThe output is a list of emails authorized to send email FROMExample output:[AWS SES] 1) [email protected]

Page 33: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Pluginaws-ses-send-ping-mail

Script will verify a given email has been 'verified' by Amazon

Page 34: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

aws-ses-verify-emailScript will submit an email for verification to amazon, and send anemail to that address

Page 35: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

aws-ses-verify-emailScript will submit an email for verification to amazon, and send anemail to that address

Page 36: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

S3 File ManagementDemo

Page 37: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

S3 File ManagementHandy for storing existing assets into S3Convert local File to S3 Storagedef s3file = new File("/tmp/test.txt").s3upload { path"folder/to/my/file/" }Upload directly from Stream:def file = request.getFile('photo') def uploadedFile =file.inputStream.s3upload(file.originalFilename) { bucket "file-upload-from-inputstream" }

Page 38: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -Grails AWS Plugin

SES ManagementAFAIK skip this - the mail plugin handles all of this// settings for mail plugin to work with SES grails { mail { host = "email-smtp.us-east-1.amazonaws.com" port = 25 username ="SESUsername" password = "SESPassword" props =["mail.smtp.starttls.enable":"true","mail.smtp.port":"587","mail.debug":"true","mail.smtp.auth":"true"] //uncomment to force all emails to one address //grails.mail.overrideAddress="[email protected]"grails.mail.default.from = "[email protected]" } }

Page 39: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

Wrapper for AWS Java SDKThis is the one to use for most powerful work of services - can accessalmost all of AWS services that JDK supportsUses AWS Web Service API wrapped in a Java LibraryError handing can be more difficult than using web service api directly

Page 40: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

Services SupportedEC2 - ELB,CloudWatch, Elastic BeanstalkRDS - Elastic Mapreduce, SDB, Dynamo, Redshift, SimpleDBS3/GlacierSES (us-east-1,us-west-2,eu-west-1 only)SQS, SWFCloudFormation,CloudFrontElastic Beanstalk, Transcoder, Opsworks(Old Chef)Cloudformation, CloudSearch, Elasticache

Page 41: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

EC2Grails service wrapper is 'amazonWebService'Call amazonWebService.ec2. - for default region, callamazonWebService.getEc2('region'). for othersRunInstancesRequest class defines parameters to launch an instance(It seems picky about nulls)use amazonWebService.runInstances() to start instancesComplete docs at:http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/

Page 42: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

RDSNot sure why you would spin up entire databases, but you can!Most practical use would be to automate snapshots of the databaseIf you have a small simple database, service is goodCannot start/top RDS instances, and pay premium to use theirlicenses if using commercial DBsIf you have the skill or have large DB requirements, set up your owndatabase - there is probably an AMI for itHas good multi-az failover (but pricey!) with PIOPS EBS Volumes (Youcan raid your own PIOPS drives!)

Page 43: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

S3manage buckets, upload/download and delete filesTransfer Manager - handles multipart uploads (big files, batch, fast!)full docs here:http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/package-summary.html

Page 44: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

Glaciercold storage for data - not immediately available on demandvaults - organize your archives and policies (where your files go)Upload files viaamazonWebService.glacier.uploadArchive(UploadArchiveRequestuploadArchiveRequest) or UploadMultiPartFiles are retrieved via 'initiateJob'Call 'listJobs' until your job is done.Can use Amazon SNS to notify you when jobs are completeWhen done get files from your vault via GetJobOutput

Page 45: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

Glacier

Page 46: Deploying, Scaling, and Running Grails on AWS and VPC

General AWS Grails Plugins -AWS SDK Plugin

SQSSimple queue serviceCreate / Delete QueuesReceive MessageCan also assign permissions and batch messagesMessages can remain in queue for 12 hours

Page 47: Deploying, Scaling, and Running Grails on AWS and VPC

ElasticWolfMore powerful than web console guiCan control things like auto-scalingCreated partly for new GovCloud because they had no UI at all initiallyManaged by sales organization instead of ITActively Maintained on Github

Page 48: Deploying, Scaling, and Running Grails on AWS and VPC

ElasticWolfDemo

Page 49: Deploying, Scaling, and Running Grails on AWS and VPC

sshoogr and gramazonsshoogr - Groovy-based DSL library for working with remote serversthrough SSH - DSL Allows:

connectingexecuting remote commandscopying files and directoriescreating tunnels in a simple and concise waygradle plugin also forproject very active (last commit 1 month ago)

gramazon - Groovy based API for Amazon EC2interface library that can be used to interact with the Amazon EC2system and control server resources on demand from your Groovyscripts or from Gradle, using a plug-in.>uses gradle to run commandsmaybe could be used as basis for a groovy version of chef orpuppet?project very active (last commit 1 month ago)gradle project template available as well as 'gradle-ssh-plugin'

Repos for these: https://github.com/aestasit/sshoogr andhttps://github.com/aestasit/gramazon-gradle

Page 50: Deploying, Scaling, and Running Grails on AWS and VPC

Autoscaling OverviewAutoscaling can be used for fault-tolernance (min 1)Most efficient user of instanceSet Policies using templates for how more servers created/terminatedControl Spot instance bit priceYou app must be able to handle 'sudden death'Make sure your debug your AMI BEFORE adding to a autoscale group(debugging failed autoscaled instances is no way to go through lifeson!)

Page 51: Deploying, Scaling, and Running Grails on AWS and VPC

Autoscaling SetupStep 1: Create Launch Config(Just like launching instance but atemplate)Step 2: Create Autoscale GroupStep 3: Create PoliciesDemo with ElasticWolf (can use web console now too)

Page 52: Deploying, Scaling, and Running Grails on AWS and VPC

Elastic BeanstalkFinally a good solution to push your application to Elastic Beanstalk on

Grails!Ken Liu now has first class citizen support in Grails for ElasticBeanstalk!Easy to set up and configure, just add keys and params toConfig.groovyUse command 'aws-eb-deploy' and 'aws-eb-stop' - that's it!Detailed online manual available at http://kenliu.net/grails-elastic-beanstalk/manual.html

Page 53: Deploying, Scaling, and Running Grails on AWS and VPC

Useful resourcesElastic Beanstalk plugin by Ken Liu: http://grails.org/plugin/aws-elastic-beanstalkElastic Beanstalk Intro @ Bobby Warner's Blog:http://www.bobbywarner.com/2011/10/14/grails-on-aws/Another Beanstalk:http://malderhout.wordpress.com/2011/02/18/deploy-grails-apps-in-3-simple-steps-to-amazon-beanstalk/Sample Beanstalk app: https://github.com/4np/grailsOnAWSOracle, EBS, and other Tips from AWS Architect Tom Laszewskihttp://cloudconclave.blogspot.com/Building an S3 Browser in Grailshttp://aws.amazon.com/articles/Amazon-S3/4000