This weblog publish was coauthored with my coworker, Jelena Keravica. Thanks for collaborating again within the day.
Introduction
With AWS Elastic Beanstalk, you may rapidly deploy and handle functions within the AWS cloud with out having to fret in regards to the infrastructure that helps these functions. AWS Elastic Beanstalk routinely handles all the main points of capability provisioning, load balancing, scaling, and software well being monitoring.
This text will clarify find out how to arrange steady deployment in your Rails software on Elastic Beanstalk utilizing Semaphore. First, we are going to initialize an setting on Elastic Beanstalk console and add some modifications to our Rails software configuration. Then, we will go on to arrange deployment on Semaphore.
Stipulations
Earlier than you start, you will want to:
- Create an AWS account
- Add your undertaking from GitHub or Bitbucket to Semaphore. Click on right here to find out how.
Initializing an Elastic Beanstalk Setting
An Elastic Beanstalk software is a logical assortment of Elastic Beanstalk elements, together with environments, variations, and setting configurations. In Elastic Beanstalk, an software is conceptually much like a folder. An setting is a model that’s deployed onto AWS assets. Every setting runs solely a single software model at a time.
Creating an Software
Step one is to create an software on the Elastic Beanstalk console. Within the higher proper nook, choose the area during which to create the Elastic Beanstalk software. It is best to in all probability decide the one closest to your location.
Subsequent, click on on “Create New Software”, and select a reputation in your Elastic Beanstalk software.
You too can do that out of your command line:
$ aws elasticbeanstalk create-application --application-name rtassignment
Creating the Setting
The following step is to create an setting. It is best to select the “Create net server” possibility.
Your predefined configuration must be set to Ruby and, for now, you may select “Single occasion” as your setting kind. You may improve to the load-balancing, autoscaling setting when the appliance is prepared for manufacturing.
For the preliminary software model, you may choose “Pattern software”. That is only a non permanent Elastic Beanstalk software which we are going to use to simply verify whether or not our configuration is appropriate.
Subsequent, you will want to decide on a URL in your software and verify its availability.
In case your software requires a database, you will want so as to add an RDS DB occasion within the following step.
Within the subsequent step, you may enter the configuration choices as proven within the image under. Including the EC2 keypair is non-compulsory, however you might want it later for extra configuration, and you’ll’t add a keypair to a operating occasion with out stopping it.
For those who don’t have an EC2 keypair, you may learn to create one right here, or, if you wish to import your personal public key created utilizing a third-party software, you may comply with these directions.
While you create a brand new setting, you may specify tags to categorize the setting. Tags will help you establish environments in value allocation studies, which is particularly helpful when you have many to handle. These are non-compulsory, so you may select to depart the fields empty.
On this instance, we’re utilizing Postgres as our DB engine, however you may select your personal from the choose field.
The final step is to outline permissions in your setting. While you create a brand new setting, AWS Elastic Beanstalk prompts you to offer two AWS Identification and Entry Administration (IAM) roles, a service position and an occasion profile.
A job is actually a set of permissions that grant entry to actions and assets in AWS. An occasion profile is a container for an IAM position that you should utilize to go position info to an EC2 occasion when the occasion begins. This permits the Elastic Beanstalk service to observe setting assets in your behalf. You may learn extra about permissions within the Elastic Beanstalk documentation.
For many environments, the service position and occasion profile that the AWS Administration Console prompts you to create with 1-click position creation while you launch your setting embody the entire permissions you want. We are going to use these within the instance.
The ultimate step is to evaluation theinformation and, while you’ve confirmed it and clicked “Launch”, the setting ought to begin initializing. It could possibly take some time when you have chosen the choice to create RDS database.
You too can do that out of your command line with the next instructions:
$ aws elasticbeanstalk create-environment --application-name rtassignment --environment-name rtassignment-env --version-label version-1 --solution-stack-name "64bit Amazon Linux 2015.03 v2.0.0 operating Ruby 2.2 (Puma)"
The answer stack identify is principally your server configuration. We’re utilizing "64bit Amazon Linux 2015.03 v2.0.0 operating Ruby 2.2 (Puma)"
for the answer stack identify, however you may discover different options that may be listed utilizing the next command:
$ aws elasticbeanstalk list-available-solution-stacks
When the setting standing turns inexperienced, you may click on the URL on the console. For those who see the welcome display screen of the pattern software, it implies that your setting has been correctly configured.
Retrieving Safety Credentials
Earlier than you progress on, you will want to retrieve safety credentials, which you’ll use afterward to offer Semaphore with entry to your software. You may get your credentials by clicking in your identify within the higher proper nook of Elastic Beanstalk administration console and deciding on “Safety credentials”.
Within the left navigation bar, click on the “Customers” possibility and create a brand new person. Select a reputation in your person, obtain the credentials and retailer them someplace secure — you will want these to configure Semaphore in one of many following steps.
Subsequent, you’ll want to outline a set of permissions for the newly created person. These are the permissions you’ll delegate to Semaphore with the intention to deploy your software. Within the customers listing, click on the username to see its web page. AWS makes use of managed insurance policies to outline these permissions, A coverage could be connected to a person or a bunch. If in case you have many customers, teams present a simple approach to handle their permissions. Nonetheless, if that is the primary time you might be utilizing Elastic Beanstalk and also you simply need to strive it out, you may connect a coverage straight to your person.
By clicking the “Connect Coverage” button underneath “Permissions”, you will notice an inventory of predefined AWS insurance policies. For those who select the AWSElasticBeanstalkFullAccess
coverage, your deployment will work , however that is often not beneficial. By following the usual safety recommendation of granting least privilege, you need to grant solely the permissions required to carry out a process.
Getting ready Your Rails Software
The Elastic Beanstalk console means that you can outline a set of setting variables in your software. The one you might be actually going to want is SECRET_KEY_BASE
. This variable is used for specifying a key which permits the periods utilized by the appliance to be verified towards a identified safe key to stop tampering. You may get it by typing bundle exec rake secret
command in your Rails undertaking folder.
Go to your Elastic Beanstalk console, choose your software setting and select “Software program configuration” underneath the “Configuration” possibility within the left navigation bar. Paste the lengthy string into the suitable discipline.
Deploying Your Rails Software with Semaphore
Now that you’ve got initialized your setting and configured your Rails software, it’s time to lastly deploy it. Go to the Semaphore dwelling web page, discover your undertaking and add a brand new deployment server. On the subsequent web page, select Elastic Beanstalk.
Selecting the Deployment Technique
For the aim of this tutorial, we are going to use the Automated deployment technique. Which means each profitable construct on the department you select will launch a deploy.
Within the subsequent step, you will want to decide on the department you want to deploy.
Getting into the AWS Credentials
Enter the AWS credentials you retrieved within the “Safety Credentials” step of this tutorial, and choose the area your software resides in. This may allow Semaphore to listing the appliance and environments you’ve within the area you specified.
Choosing the Software and the Setting
Subsequent, you will want to pick out your goal software and setting. On this instance, we see that Semaphore discovered the my-app software and its setting. Additionally, you will want to pick out the S3 bucket the place your undertaking .zip file will likely be uploaded, as a result of that is the place Elastic Beanstalk will search for your software information.
On this tutorial, we’re assuming that you’re utilizing the default Elastic Beanstalk deployment course of. Nonetheless, the identical setup on Semaphore may even work if you’re utilizing Elastic Beanstalk with Docker in a single container setting.
While you created the Elastic Beanstalk software within the earlier steps, a bucket named one thing much like elasticbeanstalk-us-west-2-057267302678
ought to have been created. It’s superb if you wish to choose another bucket with a extra descriptive identify.
You may create a brand new S3 bucket on the subsequent type by clicking the “Create new S3 Bucket” hyperlink and getting into the bucket identify. Alternatively, you may go to the S3 Administration Console and create one there, during which case you simply must hit refresh on the Semaphore web page.
Configuring the Database
Elastic Beanstalk makes use of a customized database.yml
file, and Semaphore will generate one for you.
Subsequent, you simply want to pick out your database adapter and enter the identify of your database setting (e.g. “manufacturing”).
We are going to choose Postgres, identical to we did once we created the appliance on the Elastic Beanstalk console. Your database setting identify ought to match the RACK_ENV
setting variable, which we talked about within the section titled “Getting ready Your Rails Software” .
Naming Your Server
Now that you just’ve configured the database, you may identify your server and create it.
Deploying the Software
Click on on “Deploy” to deploy your software.
Now, you simply want to attend for the deploy instructions to complete executing.
Congratulations! You’ve efficiently deployed your software to AWS Elastic Beanstalk.