{"id":19793,"date":"2015-06-03T12:03:25","date_gmt":"2015-06-03T06:33:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=19793"},"modified":"2015-08-09T22:06:16","modified_gmt":"2015-08-09T16:36:16","slug":"aws-elastic-beanstalk-grails-application","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aws-elastic-beanstalk-grails-application\/","title":{"rendered":"AWS Elastic Beanstalk ( Grails Application )"},"content":{"rendered":"<p>Ever wondered what to do if you have to make a very quick deployment of an application on the AWS Cloud ? You would launch servers, make an infrastructure and then Install applications which is somewhat a tedious process. How would it sound if the deployments are made in seconds ?<\/p>\n<p>Here <a title=\"AWS Certified Solutions Architects Team\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">is an AWS service for all the developers<\/a> and the people who do the deployments. AWS Elastic Beanstalk is what we will be talking about in this blog. With Elastic Beanstalk, you can quickly deploy and <a title=\"AWS Monitoring Services\" href=\"http:\/\/www.tothenew.com\/devops-aws\">manage applications in the AWS cloud<\/a> without worrying about the infrastructure that runs those applications.<\/p>\n<p>Have the code ? Need a quick deployment to be done ? Just make a few configuration changes, do a few clicks &amp; you are up and running !<\/p>\n<p>In Elastic Beanstalk an application can be created and under that many environments can be created. The main configuration file of EB is <strong>.ebextensions<\/strong> which Elastic Beanstalk creates on its own on the server.<\/p>\n<h3><span style=\"text-decoration: underline;color: #ff6600\"><strong><span style=\"text-decoration: underline\"><span style=\"text-decoration: underline;color: #ff6600\">The steps to deploy a Grails app are as follows :-<\/span>\u00a0<\/span><\/strong><\/span><\/h3>\n<p><span style=\"color: #000000\">1. Go to the AWS Elastic Beanstalk Console.<\/span><br \/>\n<a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/rsz_screenshot_from_2015-05-25_110441.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-19973\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/rsz_screenshot_from_2015-05-25_110441.png\" alt=\"rsz_screenshot_from_2015-05-25_110441\" width=\"601\" height=\"268\" \/><\/a><\/p>\n<p><span style=\"color: #000000\">2. Create a New Application. Choose the Type of application. For now, EB Supports Docker, PHP, Java Tomcat, Ruby etc. For this demo we will choose Tomcat 7 Java 7.<\/span><br \/>\n<a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-111814.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-19974\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-111814.png\" alt=\"Screenshot from 2015-05-25 11:18:14\" width=\"625\" height=\"261\" \/><\/a><\/p>\n<p>3. <span style=\"color: #000000\">Now, create a New Environment. Choose Web Server.<\/span><br \/>\n<a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-111918.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19989\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-111918.png\" alt=\"Screenshot from 2015-05-25 11:19:18\" width=\"1351\" height=\"444\" \/><\/a><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112034.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19990\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112034.png\" alt=\"Screenshot from 2015-05-25 11:20:34\" width=\"1344\" height=\"591\" \/><\/a><\/p>\n<p>Since at this point of time we don&#8217;t know the RDS endpoint &amp; the Elastic Beanstalk Environment URL we will choose sample application.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112058.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19991\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112058.png\" alt=\"Screenshot from 2015-05-25 11:20:58\" width=\"1343\" height=\"385\" \/><\/a><br \/>\n4.<span style=\"color: #000000\"> Select the required settings like auto-scaled or single Instance environment, VPC\/EC2. You can also select an SNS for reporting changes to your environment.\u00a0You will have to choose an existing database ( RDS ) or you can create a new one by choosing the DB option. Then, if you have chosen to do all this inside a VPC, you need to select the VPC &amp; the subnets.<\/span><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112244.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19992\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112244.png\" alt=\"Screenshot from 2015-05-25 11:22:44\" width=\"1342\" height=\"634\" \/><\/a><\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112412.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19993\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112412.png\" alt=\"Screenshot from 2015-05-25 11:24:12\" width=\"1345\" height=\"582\" \/><\/a><\/p>\n<p><span style=\"color: #ff6600\"><strong>RDS options<\/strong> :-<\/span><\/p>\n<ul>\n<li><strong>Snapshot<\/strong> : none<\/li>\n<li><strong>DB Engine<\/strong> : mysql<\/li>\n<li><strong>Instance Class<\/strong>: db.t2.micro (if you want to stay in the free tier)<\/li>\n<li><strong>Allocated Storage<\/strong>: 5 to 20 Gb (if you want to stay in the free tier)<\/li>\n<li><strong>Availability<\/strong>: Single Availability<\/li>\n<\/ul>\n<p>And now, the <strong>VPC configurations<\/strong>.<br \/>\n<a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112917.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19994\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-112917.png\" alt=\"Screenshot from 2015-05-25 11:29:17\" width=\"1342\" height=\"600\" \/><\/a><\/p>\n<p><span style=\"color: #000000\">5<\/span>.<span style=\"color: #000000\"> Elastic Beanstalk will automatically launch all the instances form an infrastructure with EC2, Security Groups, Alarms etc. You can see the events in Recent Events. You can go to configuration tab and make various configuration changes like environment type, RDS changes, VPC &amp; various variables like Heap Memory etc.<\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19995\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-113609.png\" alt=\"Screenshot from 2015-05-25 11:36:09\" width=\"1345\" height=\"640\" \/><\/p>\n<p>6.\u00a0<span style=\"color: #ff6600\"><span style=\"color: #000000\">Now, go to your Grails application server\/local machine where you create war file. You need to make some changes in <strong>DataSource.groovy<\/strong> , <strong>C<\/strong><strong>onfig. groovy, Build groovy file.<\/strong><\/span><\/span><br \/>\n<span style=\"color: #000000\"> <strong>DataSource.groovy <\/strong>file looks like this :-<\/span><br \/>\n<a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-123047.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-19997\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-123047.png\" alt=\"Screenshot from 2015-05-25 12:30:47\" width=\"1271\" height=\"701\" \/><\/a><br \/>\nComment out the lines as in the above image. Elastic Beanstalk reads only the production part. Even if you are using the H2 database use put the lines inside the production.<\/p>\n<p>[js]<br \/>\nproduction {<br \/>\ndataSource {<br \/>\nusername = &quot;{user}&quot;<br \/>\npassword = &quot;{password}&quot;<br \/>\npooled = true<br \/>\ndbCreate = &quot;update&quot;<br \/>\ndriverClassName = &quot;com.mysql.jdbc.Driver&quot;<br \/>\nurl = \u00a0\u00a0\u00a0&quot;jdbc:mysql:\/\/{endpoint}:{port_number}\/ebdb&quot;<br \/>\ndialect = org.hibernate.dialect.MySQL5InnoDBDialect<br \/>\nproperties {<br \/>\nvalidationQuery = &quot;SELECT 1&quot;<br \/>\ntestOnBorrow = true<br \/>\ntestOnReturn = true<br \/>\ntestWhileIdle = true<br \/>\ntimeBetweenEvictionRunsMillis = 1800000<br \/>\nnumTestsPerEvictionRun = 3<br \/>\nminEvictableIdleTimeMillis = 1800000<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n[\/js]<\/p>\n<p><span style=\"color: #ff6600\"><strong>You need to replace:-<\/strong><\/span><\/p>\n<p>[js]<br \/>\n{user} your RDS instance user name defined earlier.<br \/>\n{password} your RDS instance password<br \/>\n{endpoint} your RDS endpoint<br \/>\n{port} your RDS endpoint port number<br \/>\n[\/js]<\/p>\n<p>Now, in <strong>config.groovy<\/strong> find the production grails.serverURL variable under environments and put in the URL given in the Elastic Beanstalk dashboard we discussed about earlier.<\/p>\n<p>[js]<br \/>\nenvironments {<br \/>\n    production {<br \/>\n        grails.logging.jul.usebridge = false<br \/>\n        grails.serverURL = &quot;http:\/\/{environment_ name}.elasticbeanstalk.com&quot;<br \/>\n    }<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>Also in <strong>Build groovy<\/strong> file uncomment java-mysql dependency.<br \/>\nNow, create war using command:-<br \/>\n<strong>grails prod war<\/strong><\/p>\n<p>Just upload the war file in the Elastic Beanstalk Dashboard &amp; click Deploy. Previous versions can also be deployed by clicking on Application Versions page.<\/p>\n<p>In-case your war is on a server you can use the following command to get the war file from server to local.<br \/>\n<strong>sudo scp -i VPC.pem ubuntu@IP Address:\/home\/ubuntu\/rv\/target\/xyz.war \/home\/user\/Downloads<\/strong> ( To Copy from server to local )<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-181334.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-20005\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/05\/Screenshot-from-2015-05-25-181334.png\" alt=\"Screenshot from 2015-05-25 18:13:34\" width=\"461\" height=\"441\" \/><\/a><\/p>\n<p><span style=\"color: #ff6600\"><strong>You are finally done. Elastic beanstalk comes very handy when you need rapid deployments with all the AWS services configured for production use with minimal configuration changes.<\/strong><\/span><\/p>\n<p><span style=\"color: #ff6600\"><strong>\u00a0<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wondered what to do if you have to make a very quick deployment of an application on the AWS Cloud ? You would launch servers, make an infrastructure and then Install applications which is somewhat a tedious process. How would it sound if the deployments are made in seconds ? Here is an AWS [&hellip;]<\/p>\n","protected":false},"author":174,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":6},"categories":[1174,7],"tags":[248,1838,1837,1327,4840],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19793"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/174"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=19793"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19793\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=19793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=19793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=19793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}