Today I released a Python script called quick-deploy-java that makes it easier to deploy multiple Java applications (WARs) to a single Elastic Beanstalk instance.
Want to give it a shot? Clone the repo and follow along with this tutorial.
Step 1: Create a directory for your application and navigate to that directory
We’ll call this eb-test
. We assume that you’ll do this from the same directory that this TUTORIAL.md
file is located. If you do not the instructions later will need to incorporate the proper paths.
1 2 |
|
Step 2: Run eb init
to create your application in Elastic Beanstalk
1
|
|
I used the following values:
Region – us-east-1
1 2 3 4 5 6 7 8 9 10 11 |
|
Application name – eb-test
1 2 3 |
|
Platform – Tomcat
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Platform version – Tomcat 8 Java 8
1 2 3 4 5 6 7 |
|
SSH – yes
1 2 |
|
Keypair – existing
I already had a keypair called aws-eb that I use. You can reuse an existing one or create a new one. It shouldn’t matter.
1 2 3 4 |
|
Step 3: Create a testing environment
Since no applications are in this directory it will also launch the sample application. On my system this step took about 4 minutes.
1
|
|
The output you’ll see will start with something similar to this:
1 2 3 4 5 |
|
Once it is done you’ll see this:
1
|
|
Step 4: Validate that the default environment is running
1
|
|
You should see a page in your web browser that looks like this:
Step 5: Deploy the first toy application by itself
1 2 3 4 5 |
|
This may take several minutes. Once it is complete you can verify that it is running by doing this:
1
|
|
In your browser you should see a simple page that says something like this:
1
|
|
The random number at the end will be different.
At this point you’ve deployed a single application to a single instance. Now we’ll deploy three applications to the same instance.
Step 6: Deploy three applications to the same instance
1 2 3 4 5 6 7 |
|
This took about 4 minutes on my system. At this point open the application again:
1
|
|
Make sure that the random number has changed. This shows that you’ve got a new instance of the application.
Now add /1
to the URL in your address bar and load the page. You should see the same message but again with another new number. This shows that you have a second copy of the application running at a new path.
Finally replace /1
with /2
in the URL in your address bar and load the page. You should see exactly this message in your browser:
1
|
|
If everything worked out you now have an Elastic Beanstalk configuration that is running three applications in a single instance. application1
is running at the root and at the 1
path while application1
is running at the 2
path.
Step 7: Terminate your application
Make sure you terminate your application when you’re done.
1
|
|
If you forget to do this step Amazon will keep your application running and keep billing you! If you want to be extra thorough go into the AWS Elastic Beanstalk console and delete the application completely.
You should also go into S3 and delete any files that are left behind. They don’t take up much space but keeping S3 tidy for when you start making real use of Elastic Beanstalk makes sense.