⬆️ ⬇️

Publishing an application to Elastic Beanstalk

Hello! image



Today I’ll tell you how easy it is to create applications in Elastic Beanstalk and publish them directly from Git!



First of all, I suggest installing command line utilities for EB. You can download from here , or use my script to install and update the basic utilities for this article .

')

Installed. In the console, we will have the eb command, with which we will begin.



1. Creating an application



First, create an application folder and initialize the Git repository. For example:

$ mkdir ~/Work/testapp/ && cd ~/Work/testapp/ $ git init 


Create an Elastic Beanstalk application

 $ eb init 
EB Questions
 To get your AWS Access Key ID and Secret Access Key, 
   visit "https://aws-portal.amazon.com/gp/aws/securityCredentials".
 Enter your AWS Access Key ID: AKIA ********** 7KAQ
 Enter your AWS Secret Access Key: puKfEWZwNr ******************* wx7iwU / U6NnE
 Select an AWS Elastic Beanstalk service region.
 Available service regions are:
 1) US East (Virginia)
 2) US West (Oregon)
 3) US West (North California)
 4) EU West (Ireland)
 5) Asia Pacific (Singapore)
 6) Asia Pacific (Tokyo)
 7) Asia Pacific (Sydney)
 8) South America (Sao Paulo)
 Select: (1 to 8): 1
 Enter an AWS Elastic Beanstalk application name (auto-generated value is "testapp"): testapp
 Enter an AWS Elastic Beanstalk environment name (auto-generated value is "testapp-env"): 
 Select a solution stack.
 Available solution stacks are:
 1) 32bit Amazon Linux running PHP 5.4
 2) 64bit Amazon Linux running PHP 5.4
 3) 32bit Amazon Linux running PHP 5.3
 4) 64bit Amazon Linux running PHP 5.3
 5) 64bit Windows Server 2008 R2 running IIS 7.5
 6) 64bit Windows Server 2012 running IIS 8
 7) 32bit Amazon Linux running Tomcat 7
 8) 64bit Amazon Linux running Tomcat 7
 9) 32bit Amazon Linux running Tomcat 6
 10) 64bit Amazon Linux running Tomcat 6
 11) 32bit Amazon Linux running Python
 12) 64bit Amazon Linux running Python
 13) 32bit Amazon Linux running Ruby 1.8.7
 14) 64bit Amazon Linux running Ruby 1.8.7
 15) 32bit Amazon Linux running Ruby 1.9.3
 16) 64bit Amazon Linux running Ruby 1.9.3
 Select: (1 to 16): 2
 Create an RDS DB Instance?  [y / n]: n
 Updated AWS Credential file at "/home/korjik/.elasticbeanstalk/aws_credential_file". 


Fine! In the console, we will have the application:

image



Let's run it through the CLI:

 $ eb start 
Application launch
 Starting application "testapp".
 Waiting for environment "testapp-env" to launch.
 2012-12-21 11:36:54 INFO createEnvironment is starting.
 2012-12-21 11:37:00 INFO Using elasticcasestalk-us-east-1-8 ****** 7906425 as Amazon S3 storage bucket for environment data.
 2012-12-21 11:37:35 INFO Created load balancer named: awseb-em-AWSEBLoa-3Y756XH4GS6C
 2012-12-21 11:37:51 INFO Created security group named: awseb-e-mcmpmiq7vv-stack-AWSEBSecurityGroup-1P8Y0FB06SVMD
 2012-12-21 11:37:57 INFO Created Auto Scaling launch configuration named: awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingLaunchConfiguration-1PPFVPGQK4PV8
 2012-12-21 11:39:09 INFO Waiting for EC2 instances to launch.  This may take a few minutes.
 2012-12-21 11:39:09 INFO Created Auto Scaling group named: awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingGroup-1WLKAEZBZ8ZGT
 2012-12-21 11:40:45 INFO Created Auto Scaling group policy names: arn: aws: autoscaling: us-east-1: 8 ****** 7906425: scalingPolicy: 8d0accbb-fa54-483a-a3c0-8b91921a738e : autoScalingGroupName / awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingGroup-1WLKAEZBZ8ZGT: policyName / awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingScaleDownPolicy-184TBBCOHLRB3
 2012-12-21 11:40:50 INFO Created CloudWatch alarm named: awseb-e-mcmpmiq7vv-stack-AWSEBCloudwatchAlarmLow-WZWD04T7WB4O
 2012-12-21 11:40:53 INFO Created Auto Scaling group policy names: arn: aws: autoscaling: us-east-1: 8 ****** 7906425: scalingPolicy: acc43498-d4ce-4421-896b-84ea7eb05fb2 : autoScalingGroupName / awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingGroup-1WLKAEZBZ8ZGT: policyName / awseb-e-mcmpmiq7vv-stack-AWSEBAutoScalingScaleUpPolicy-1GZEQ8O807OFD
 2012-12-21 11:40:56 INFO Created CloudWatch alarm named: awseb-e-mcmpmiq7vv-stack-AWSEBCloudwatchAlarmHigh-XLWNREY9ZVKY
 Application is available at "testapp-env-p3n7aesmip.elasticbeanstalk.com".


Next, install the scripts for Git in the repository:

 $ cp -r ~/AWS_CLI_TOOLS/AWS-ElasticBeanstalk-CLI-2.3/AWSDevTools/Linux/* . $ ./AWSDevTools-RepositorySetup.sh 


The necessary files appeared in the .git folder:

 $ ll .git/AWSDevTools/ total 24 drwxr-xr-x 3 korjik korjik 4096 Dec 21 12:27 . drwxrwxr-x 8 korjik korjik 4096 Dec 21 12:27 .. drwxr-xr-x 2 korjik korjik 4096 Dec 21 12:27 aws -rwxr-xr-x 1 korjik korjik 4372 Dec 21 12:27 aws.elasticbeanstalk.config -rwxr-xr-x 1 korjik korjik 2798 Dec 21 12:27 aws.elasticbeanstalk.push 


2. Depla application



So, our application is ready, it needs to be covered.



Let's create the simplest thing that came to mind:

 $ echo "<?php phpinfo(); ?>" > index.php 


Add and commit to git:

 $ git add index.php $ git commit -m "PHP INFO" 


Well, actually warm:

 $ git aws.push --environment "testapp-env" Counting objects: 3, done. Writing objects: 100% (3/3), 240 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: To https://AKIAII*********7KAQ:20121221T103218Z8abd2f8768ce64d97f85dd0902b5f8efadcf8148a227924464fe8e6fc41998a1@git.elasticbeanstalk.us-east-1.amazonaws.com/v1/repos/74657374617070/commitid/39383466343734663539393639396130316535336661353933656461383661333461353766636632/environment/746573746170702d656e76 + 755988e...984f474 HEAD -> master (forced update) 20121221T103218Z8abd2f8768ce64d97f85dd0902b5f8efadcf8148a227924464fe8e6fc41998a1@git.elasticbeanstalk.us-east-1.amazonaws.com/v1/repos/74657374617070/commitid/39383466343734663539393639396130316535336661353933656461383661333461353766636632/environment/746573746170702d656e76 $ git aws.push --environment "testapp-env" Counting objects: 3, done. Writing objects: 100% (3/3), 240 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: To https://AKIAII*********7KAQ:20121221T103218Z8abd2f8768ce64d97f85dd0902b5f8efadcf8148a227924464fe8e6fc41998a1@git.elasticbeanstalk.us-east-1.amazonaws.com/v1/repos/74657374617070/commitid/39383466343734663539393639396130316535336661353933656461383661333461353766636632/environment/746573746170702d656e76 + 755988e...984f474 HEAD -> master (forced update) 


Check status:

 $ eb status URL : testapp-env-yp333cyrp2.elasticbeanstalk.com Status : Updating Health : Grey 


When the status is Ready check!



Well, the application is up and running:

image



In fact, everything is extremely simple. You can easily create branches of an application using eb branch and deploy from Git as you like and wherever you go. In the article, the address of the application changed - these were different tests. When the address is not changed.



In general, I highly recommend reading about Elastic Beanstalk .



Do you use EB? Tell something interesting?

Source: https://habr.com/ru/post/163489/



All Articles