The only problem with AWS is that it is really versatile. It is packed with an ever-increasing number of services. Each of these services continues to evolve, taking on more functionality and flexibility. Naturally, some of us find this overwhelming.
I am not interested in the details and its crazy configurations. I don't care for the Dockers, Kubernetes, Serverless, VPC, subnets, availability zones, Security Group, EC2 Instances and all that nonsense. I have a business problem and I have a working code. I just want to deploy this in the cloud and focus my business rather than messing around.
Is that your state of mind? Don't worry; you are not alone. AWS cares for you, making Elastic Beanstalk just for you. This is one of the many services in AWS that focus on providing a simplified interface to the core services.
With Elastic Beanstalk, we can quickly deploy and manage applications in AWS without bothering about the details of the underlying infrastructure and its configuration and other complexities. We just upload the application code, and then it takes care of the details of capacity provisioning, load balancing, scaling, application health monitoring, and all that is required!
So you have a working NodeJS application. It works in the local environment; now, you want to deploy it on the cloud and let the world benefit from your innovation. Certainly don't want to waste your energy and passion on choosing the EC2 instances and the VPC or security group configurations. You don't care for the IAM. You just want to deploy the application and start selling subscriptions.
Certainly, we can do that. Let's check how. We create the AWS account and start working on it.
Jump over to the Elastic Beanstalk console and follow the steps:
Provide Application Name: HelloServer. In Platform, choose NodeJS, and pick the latest versions from the dropdown. Then, select "Upload your code" and choose the local file.
Finally, click on "Create environment, " which will trigger the ElasticBeanstalk environment creation. That takes a few minutes. Scan through the logs it generates - if you are curious to see what it is doing in the background. The Elastic Beanstalk will create all that you need - to run the scalable web server. It will create the VPC, security groups, EC2 instance, auto-scaling group, load balancer, and everything!
Once done, it will provide a link to the application deployed on the server. Click that link, and you should see the deployed application.
And, of course, we can update the code by clicking on "Upload and deploy." Update a new zip file, and Elastic Beanstalk will deploy it correctly. Again, we don't have to worry about any servers or restarts. Just provide the updated code, and Elastic Beanstalk manages the rest.
This was a simple web server. However, the same process can be used to deploy any application regardless of the complexity. AWS provides us with sample starter applications for a variety of scenarios. And it does not stop here. Elastic Beanstalk has a lot more than this small teaser. This blog covers it all. Before that, let us check out some core concepts and terms.
Every technology has a language. Understanding that language makes it easy to understand the technology. Elastic Beanstalk refers to these core terms:
As one can guess, an application is what we are building for the user to use. It is what is exported to the world.
Any application requires a platform to run. It combines an operating system, programming language runtime, web server, application server, and other Elastic Beanstalk components. The application we develop is meant to run on a particular platform. For example, the above application is based on NodeJS.
An application is the outcome of what is running inside Elastic Beanstalk. An environment is the actual set of AWS resources that support an application deployed in Elastic Beanstalk. We can have different versions of the application deployed in different environments. This is the typical deployment pipeline that includes different environments for dev, test, prod, etc.
Depending upon the type of workload, we can choose between two environment tiers - web server and worker. As the names suggest, the web server tier is meant to build a web server that is always on and synchronous. On the other hand, the worker is tailored for asynchronous bulk processing of requests. Often a combination of the two is all we need for an application of decent complexity.
Command Line Interface
Some people do not like working on the web interface. They prefer the command line and the black screen. Elastic Beanstalk provides a powerful command line utility. Open the GitHub Repository. That gives you detailed instructions about how to clone the repository and run the script to install the CLI.
pip install virtualenv
Clone the git repository:
python ./aws-elastic-beanstalk-cli-setup/scripts/ebcli_installer.py- if you are using Mac/Linux
That will run for a few seconds and finally, give you a couple of commands to update the system PATH. That will ensure the installed eb executable is available for use on the prompt. With the eb installed, we go ahead to configure it. That is equally simple.
Select a default region 1) us-east-1 : US East (N. Virginia) 2) us-west-1 : US West (N. California) 3) us-west-2 : US West (Oregon) 4) eu-west-1 : EU (Ireland) 5) eu-central-1 : EU (Frankfurt) 6) ap-south-1 : Asia Pacific (Mumbai) 7) ap-southeast-1 : Asia Pacific (Singapore) 8) ap-southeast-2 : Asia Pacific (Sydney) 9) ap-northeast-1 : Asia Pacific (Tokyo) 10) ap-northeast-2 : Asia Pacific (Seoul) 11) sa-east-1 : South America (Sao Paulo) 12) cn-north-1 : China (Beijing) 13) cn-northwest-1 : China (Ningxia) 14) us-east-2 : US East (Ohio) 15) ca-central-1 : Canada (Central) 16) eu-west-2 : EU (London) 17) eu-west-3 : EU (Paris) 18) eu-north-1 : EU (Stockholm) 19) eu-south-1 : EU (Milano) 20) ap-east-1 : Asia Pacific (Hong Kong) 21) me-south-1 : Middle East (Bahrain) 22) af-south-1 : Africa (Cape Town) (default is 3): 1 You have not yet set up your credentials or your credentials are incorrect You must provide your credentials. (aws-access-id): AKIA4VCC4EEKTQBHLOVD (aws-secret-key): YCp6e9Z+h5NLSXWKi+SS4Nn5wJSL2LhZ+AUkhtis Select an application to use 1) [ Create new Application ] (default is 1): Enter Application Name (default is "learn"): learn Application eb has been created. Select a platform. 1) .NET Core on Linux 2) .NET on Windows Server 3) Docker 4) Go 5) Java 6) Node.js 7) PHP 8) Packer 9) Python 10) Ruby 11) Tomcat (make a selection): 6 Select a platform branch. 1) Node.js 16 running on 64bit Amazon Linux 2 2) Node.js 14 running on 64bit Amazon Linux 2 (default is 1): Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization Do you want to set up SSH for your instances? (Y/n): Select a keypair. 1) [ Create new KeyPair ] (default is 1): 1 Type a keypair name. (Default is aws-eb): Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in C:\Users\soleg\.ssh\aws-eb Your public key has been saved in C:\Users\soleg\.ssh\aws-eb.pub The key fingerprint is: SHA256:4toHdd27tDqIQA18/wrxJUNN+o1qmEpvy4gjd5aqxFk aws-eb The key's randomart image is: +---[RSA 3072]----+ | . o. | | o . ... | | + o.. . | | . + =.oo. | | E...S+ =o .. | | . o .o..o... o | | + o+oooo . o | | .. o=+=+.o . o | | .++=+o+. .o | +----[SHA256]-----+ WARNING: Uploaded SSH public key for "aws-eb" into EC2 for region us-east-1.
The Elastic Beanstalk is now configured, and you are ready to go.
ebs create to start a new project. Accept the defaults. It will create and deploy the application on AWS, and give you the sample starting template code.
$ >eb create Enter Environment Name (default is learn-dev): Enter DNS CNAME prefix (default is learn-dev): Select a load balancer type 1) classic 2) application 3) network (default is 2): Would you like to enable Spot Fleet requests for this environment? (y/N): NOTE: The current directory does not contain any source code. Elastic Beanstalk is launching the sample application instead. Do you want to download the sample application into the current directory? (Y/n): INFO: Downloading sample application to the current directory. INFO: Download complete. Environment details for: learn-dev Application name: learn Region: us-east-1 Deployed Version: Sample Application Environment ID: e-xgrqzywem4 Platform: arn:aws:elasticbeanstalk:us-east-1::platform/Node.js 16 running on 64bit Amazon Linux 2/5.6.2 Tier: WebServer-Standard-1.0 CNAME: learn-dev.us-east-1.elasticbeanstalk.com Updated: 2022-12-28 13:08:14.070000+00:00 Printing Status: 2022-12-28 13:08:12 INFO createEnvironment is starting. 2022-12-28 13:08:14 INFO Using elasticbeanstalk-us-east-1-869871132949 as Amazon S3 storage bucket for environment data. 2022-12-28 13:08:36 INFO Created target group named: arn:aws:elasticloadbalancing:us-east-1:869871132949:targetgroup/awseb--AWSEB-CQFFCFXR2EZH/70ac4d6ef71dc9b7 2022-12-28 13:08:36 INFO Created security group named: sg-0694c20912f435b4b 2022-12-28 13:08:52 INFO Created security group named: awseb-e-xgrqzywem4-stack-AWSEBSecurityGroup-1OWYHSV9HUN1Y 2022-12-28 13:08:52 INFO Created Auto Scaling launch configuration named: awseb-e-xgrqzywem4-stack-AWSEBAutoScalingLaunchConfiguration-6NjCpf6hvDlt 2022-12-28 13:09:54 INFO Created Auto Scaling group named: awseb-e-xgrqzywem4-stack-AWSEBAutoScalingGroup-1CZFCH7848R8L 2022-12-28 13:09:54 INFO Waiting for EC2 instances to launch. This may take a few minutes. 2022-12-28 13:10:09 INFO Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:869871132949:scalingPolicy:ee93a724-9b23-478f-9499-4a7be540fd15:autoScalingGroupName/awseb-e-xgrqzywem4-stack-AWSEBAutoScalingGroup-1CZFCH7848R8L:policyName/awseb-e-xgrqzywem4-stack-AWSEBAutoScalingScaleUpPolicy-BLiZJqB5azw8 2022-12-28 13:10:09 INFO Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:869871132949:scalingPolicy:c75d1b93-9440-4654-8724-adcf30d2a73e:autoScalingGroupName/awseb-e-xgrqzywem4-stack-AWSEBAutoScalingGroup-1CZFCH7848R8L:policyName/awseb-e-xgrqzywem4-stack-AWSEBAutoScalingScaleDownPolicy-mVpMeVmINA60 2022-12-28 13:10:09 INFO Created CloudWatch alarm named: awseb-e-xgrqzywem4-stack-AWSEBCloudwatchAlarmHigh-1RTKO5140EQYK 2022-12-28 13:10:09 INFO Created CloudWatch alarm named: awseb-e-xgrqzywem4-stack-AWSEBCloudwatchAlarmLow-19ZRCCZT040AR 2022-12-28 13:10:45 INFO Created load balancer named: arn:aws:elasticloadbalancing:us-east-1:869871132949:loadbalancer/app/awseb-AWSEB-OTWRU4CFEYPK/d76e76d690a4b9be 2022-12-28 13:10:45 INFO Created Load Balancer listener named: arn:aws:elasticloadbalancing:us-east-1:869871132949:listener/app/awseb-AWSEB-OTWRU4CFEYPK/d76e76d690a4b9be/d7621ebcb828a139 2022-12-28 13:10:48 INFO Instance deployment: You didn't specify a Node.js version in the 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version. 2022-12-28 13:10:53 INFO Instance deployment completed successfully. 2022-12-28 13:11:08 INFO Application available at learn-dev.us-east-1.elasticbeanstalk.com. 2022-12-28 13:11:09 INFO Successfully launched environment: learn-dev
Just edit the code as you need and deploy it again.