If you are a beginner or have little time, configuring the environment for your application may be too complicated and time-consuming. You need to consider monitoring, logs, security groups, VMs, backups, etc. You can make a mistake that compromises your application and makes it vulnerable to various attacks. The service can help you with all this. Sit back and enjoy a hands-on Elastic Beanstalk tutorial.
In today’s article, learn more about a service that provides a solution to most of the problems you might have with deploying applications on AWS. What exactly is that?
What is an elastic beanstalk?
Elastic Beanstalk (EB) can prepare an entire AWS environment for you. This way, you can deploy your application and prepare the environment for it in minutes. EB will prepare EC2 instances, RDS database, auto-scaling load balancer, health checks, HTTPS certificates, logging, and much more. Just choose one of the available predefined templates (among them Go, Java, Python, PHP, Nodejs, and Docker), decide how you want the environment to behave, and you’re good to go. You can also easily deploy a new version of your app.
Under the hood, EB is a special agent that uses predefined CloudFormation templates to set up a new environment and maintain control over it.
Benefits of the Elastic Beanstalk
There are several reasons why EB may be the optimal choice for you:
automates the creation of infrastructure, taking into account AWS best practices guidelines, so you don’t have to click through many different AWS services,
all the required configurations are in one place, so it is easy to find the ones you need to change,
you can automate this even more with the EB CLI console tool,
EB supports plugins that you can save along with your code. Plugins can contain configurations for various services, including EB itself. This allows you to start your journey with infrastructure as code (IaC) before moving on to more advanced solutions such as CloudFormation or Terraform,
you can easily create many environments for one application (dev, staging, prod, etc.),
it’s free (but you have to pay for the resources it created),
it’s PAAS (platform-as-a-code), so you don’t have to worry about security patches and updates to infrastructure elements.
Sounds good, right? Let’s get to the real Elastic Beanstalk tutorial!
Check out the TSH Node.js development standard, which includes support for deployment with Elastic Beanstalk.
With this standard, you can build scalable Node.js applications faster.
Getting started with Elastic Beanstalk
Just log into your AWS console and search for Elastic Beanstalk. When you get to the EB welcome page, click on the “Create Application” button. An EB application is a representation of your code. Next, you need to enter a name for the application and select a template that the application will rely on.
https://docs.aws.amazon.com
This is relevant because Amazon Linux 2 allows you to use the docker-compose.yml file and build Docker images directly. If you chose the first version, you would have to use the dockerrun.aws.json files, which requires additional work and knowledge.
It’s usually a good idea to use the recommended version in the Platform Version field (EB keeps its templates updated regularly).
Below you should select the code you want to run in the new environment. If you don’t have anything ready, you can choose the Demo app. After that, a straightforward code will be uploaded, so you can start experimenting with EB immediately. Here is some code ready for you to use in this tutorial.
https://docs.aws.amazon.com
This application creates random data, stores it in a database, and then lists all the records created (one record is created per request).
Now you can click the “Create App” button, and you’re ready. Well… that’s not it. There are still a few things to configure, but Elastic Beanstalk makes it easy. For now, you should go to the “Configure more options” button.
https://docs.aws.amazon.com
You can select one of the presets. This tutorial uses the High Availability preference. Below you can see 12 modules that can be configured. After selecting a preset, some of them will be updated. What’s in them? Quite a few highlights:
Software – here, you can enable rotatable logging and choose a proxy server if needed. You can also set environment properties that will be passed to the application as environment variables.
Instance – here, you can specify the type of storage you want to use along with EC2 security groups if you want to use any previously created ones.
Capacity – here, you can enable load balancing and specify autoscaling parameters for your environment (how many instances you want to use and which metric determines their addition/removal).
Load balancer – here, you can choose the type of load balancer, figure listeners, and processes for it. You can also enable logging.
Continuous Updates and Deployment – here, you can specify the deployment policy for our auto-scaling application.
Security – You can edit EC2 security stuff (EC2 key pair, IAM instance profile).
Monitoring – here, you can configure reports on the status of your application and log them to CloudWatch.
Managed Updates – You can specify if and when you want to update the version of the EB platform if AWS prepares a new version.
Notifications – Here, you can enter an email address to be notified of critical environment events such as crashes.
VPC – You can configure your EB environment to be part of a VPC.
Database – EB can create a database for you and send connectivity options to your application via environment parameters (but they won’t be visible in the Software module).
Tags – You can add some tags to make your environment easier to find.
As you can see, there is a lot. Only a few of these modules will be modified in this tutorial. First, you should get a Postgres database where the data will be stored. For this, it is necessary to modify the Database module. Here are the selected options:
https://docs.aws.amazon.com
As mentioned earlier, connection parameters will be available as environment parameters. Here’s an example of how you can access them in Nest.js.
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Product } from './product.model';
@Module({
import: [
TypeOrmModule.forRoot({
type: 'Postgres',
host: process.env.RDS_HOSTNAME,
port: parseInt(process.env.RDS_PORT),
username: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
database: process.env.RDS_DB_NAME,
entities: [Product],
sync: true
}),
TypeOrmModule.forFeature([Product]),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
view rawapp.module.ts hosted with ❤ on GitHub
After saving the database changes, it’s time for the Software section. In the Container Options section, None is selected because the sample application does not need a proxy. Additionally, logging is enabled.
You will need to modify the default process to change the status check path.
Change it to /health.
Now you need to click on the Create App button. You will be able to track the application deployment progress.
Creating an environment shouldn’t take more than 10 minutes unless you have a time-consuming image creation process or AWS is very busy with other things. As you can see from the log, EB creates all the required things like security and log groups. Subsequently, the RDS, load balancer, and EC2 instances are created and configured.
Once the entire process is complete, you should be automatically redirected to the dashboard of the new environment.
As you can see, the environment is healthy, and you can now use it with the provided URL. Everything is working!
Conclusion
As you can see, deploying an application to a well-prepared AWS environment is relatively easy and time-saving. I’d like to introduce you to the EB CLI, extensions, and a few other highlights, but let’s save that for another time. For homework, please look at the application I deployed today.
Let’s Recap What we have learned till now.
EB supports plugins that you can save along with your code. Plugins can contain configurations for various services, including EB itself. This allows you to start your journey with infrastructure as code (IaC) before moving on to more advanced solutions such as CloudFormation or Terraform.
Elastic Beanstalk (EB) can prepare an entire AWS environment for you. This way, you can deploy your application and prepare the environment for it in minutes. EB will prepare EC2 instances, RDS database, auto-scaling load balancer, health checks, HTTPS certificates, logging, and more.
Amazon Linux 2 allows you to use the docker-compose.yml file and build Docker images directly. If you chose the first version, you would have to use the dockerrun.aws.json files, which requires additional work and knowledge.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.
I am a Machine Learning Enthusiast. Done some Industry level projects on Data Science and Machine Learning. Have Certifications in Python and ML from trusted sources like data camp and Skills vertex. My Goal in life is to perceive a career in Data Industry.
We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.
Show details
Powered By
Cookies
This site uses cookies to ensure that you get the best experience possible. To learn more about how we use cookies, please refer to our Privacy Policy & Cookies Policy.
brahmaid
It is needed for personalizing the website.
csrftoken
This cookie is used to prevent Cross-site request forgery (often abbreviated as CSRF) attacks of the website
Identityid
Preserves the login/logout state of users across the whole site.
sessionid
Preserves users' states across page requests.
g_state
Google One-Tap login adds this g_state cookie to set the user status on how they interact with the One-Tap modal.
MUID
Used by Microsoft Clarity, to store and track visits across websites.
_clck
Used by Microsoft Clarity, Persists the Clarity User ID and preferences, unique to that site, on the browser. This ensures that behavior in subsequent visits to the same site will be attributed to the same user ID.
_clsk
Used by Microsoft Clarity, Connects multiple page views by a user into a single Clarity session recording.
SRM_I
Collects user data is specifically adapted to the user or device. The user can also be followed outside of the loaded website, creating a picture of the visitor's behavior.
SM
Use to measure the use of the website for internal analytics
CLID
The cookie is set by embedded Microsoft Clarity scripts. The purpose of this cookie is for heatmap and session recording.
SRM_B
Collected user data is specifically adapted to the user or device. The user can also be followed outside of the loaded website, creating a picture of the visitor's behavior.
_gid
This cookie is installed by Google Analytics. The cookie is used to store information of how visitors use a website and helps in creating an analytics report of how the website is doing. The data collected includes the number of visitors, the source where they have come from, and the pages visited in an anonymous form.
_ga_#
Used by Google Analytics, to store and count pageviews.
_gat_#
Used by Google Analytics to collect data on the number of times a user has visited the website as well as dates for the first and most recent visit.
collect
Used to send data to Google Analytics about the visitor's device and behavior. Tracks the visitor across devices and marketing channels.
AEC
cookies ensure that requests within a browsing session are made by the user, and not by other sites.
G_ENABLED_IDPS
use the cookie when customers want to make a referral from their gmail contacts; it helps auth the gmail account.
test_cookie
This cookie is set by DoubleClick (which is owned by Google) to determine if the website visitor's browser supports cookies.
_we_us
this is used to send push notification using webengage.
WebKlipperAuth
used by webenage to track auth of webenagage.
ln_or
Linkedin sets this cookie to registers statistical data on users' behavior on the website for internal analytics.
JSESSIONID
Use to maintain an anonymous user session by the server.
li_rm
Used as part of the LinkedIn Remember Me feature and is set when a user clicks Remember Me on the device to make it easier for him or her to sign in to that device.
AnalyticsSyncHistory
Used to store information about the time a sync with the lms_analytics cookie took place for users in the Designated Countries.
lms_analytics
Used to store information about the time a sync with the AnalyticsSyncHistory cookie took place for users in the Designated Countries.
liap
Cookie used for Sign-in with Linkedin and/or to allow for the Linkedin follow feature.
visit
allow for the Linkedin follow feature.
li_at
often used to identify you, including your name, interests, and previous activity.
s_plt
Tracks the time that the previous page took to load
lang
Used to remember a user's language setting to ensure LinkedIn.com displays in the language selected by the user in their settings
s_tp
Tracks percent of page viewed
AMCV_14215E3D5995C57C0A495C55%40AdobeOrg
Indicates the start of a session for Adobe Experience Cloud
s_pltp
Provides page name value (URL) for use by Adobe Analytics
s_tslv
Used to retain and fetch time since last visit in Adobe Analytics
li_theme
Remembers a user's display preference/theme setting
li_theme_set
Remembers which users have updated their display / theme preferences
We do not use cookies of this type.
_gcl_au
Used by Google Adsense, to store and track conversions.
SID
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
SAPISID
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
__Secure-#
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
APISID
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
SSID
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
HSID
Save certain preferences, for example the number of search results per page or activation of the SafeSearch Filter. Adjusts the ads that appear in Google Search.
DV
These cookies are used for the purpose of targeted advertising.
NID
These cookies are used for the purpose of targeted advertising.
1P_JAR
These cookies are used to gather website statistics, and track conversion rates.
OTZ
Aggregate analysis of website visitors
_fbp
This cookie is set by Facebook to deliver advertisements when they are on Facebook or a digital platform powered by Facebook advertising after visiting this website.
fr
Contains a unique browser and user ID, used for targeted advertising.
bscookie
Used by LinkedIn to track the use of embedded services.
lidc
Used by LinkedIn for tracking the use of embedded services.
bcookie
Used by LinkedIn to track the use of embedded services.
aam_uuid
Use these cookies to assign a unique ID when users visit a website.
UserMatchHistory
These cookies are set by LinkedIn for advertising purposes, including: tracking visitors so that more relevant ads can be presented, allowing users to use the 'Apply with LinkedIn' or the 'Sign-in with LinkedIn' functions, collecting information about how visitors use the site, etc.
li_sugr
Used to make a probabilistic match of a user's identity outside the Designated Countries
MR
Used to collect information for analytics purposes.
ANONCHK
Used to store session ID for a users session to ensure that clicks from adverts on the Bing search engine are verified for reporting purposes and for personalisation
We do not use cookies of this type.
Cookie declaration last updated on 24/03/2023 by Analytics Vidhya.
Cookies are small text files that can be used by websites to make a user's experience more efficient. The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies, we need your permission. This site uses different types of cookies. Some cookies are placed by third-party services that appear on our pages. Learn more about who we are, how you can contact us, and how we process personal data in our Privacy Policy.