More Elastic Beanstalk example applications and tutorials for Java
This section provides additional applications and tutorials. The QuickStart for Java and QuickStart for Java on Tomcat topics located earlier in this topic walk you through launching a sample Java application with the EB CLI.
To get started with Java applications on AWS Elastic Beanstalk, all you need is an application source bundle to upload as your first application version and to deploy to an environment. When you create an environment, Elastic Beanstalk allocates all of the AWS resources needed to run a scalable web application.
Launching an environment with a sample Java application
Elastic Beanstalk provides single page sample applications for each platform as well as more complex examples that show the use of additional AWS resources such as Amazon RDS and language or platform-specific features and APIs.
The single page samples are the same code that you get when you create an environment without supplying your own source code. The more complex examples are hosted on GitHub and may need to be compiled or built prior to deploying to an Elastic Beanstalk environment.
Name |
Supported versions |
Environment type |
Source |
Description |
---|---|---|---|---|
Tomcat (single page) |
All Tomcat with Corretto platform branches |
Web Server Worker |
Tomcat web application with a single page ( For worker environments, this sample includes a If you enable X-Ray integration on an environment running this sample, the application shows additional content regarding X-Ray and provides an option to generate debug information that you can view in the X-Ray console. |
|
Corretto (single page) |
Corretto 11 Corretto 8 |
Web Server |
Corretto application with If you enable X-Ray integration on an environment running this sample, the application shows additional content regarding X-Ray and provides an option to generate debug information that you can view in the X-Ray console. |
|
Scorekeep |
Java 8 | Web Server | Clone the repo at GitHub.com |
Scorekeep is a RESTful web API that uses the Spring framework to provide an interface for creating and managing users, sessions, and games. The API is bundles with an Angular 1.5 web app that consumes the API over HTTP. The application uses features of the Java SE platform to download dependencies and build on-instance, minimizing the size of the souce
bundle. The application also includes nginx configuration files that override the default configuration to serve the frontend web app statically
on port 80 through the proxy, and route requests to paths under Scorekeep also includes an See the readme for instructions or use the AWS X-Ray getting started tutorial to try the application with X-Ray. |
Does it Have Snakes? |
Tomcat 8 with Java 8 | Web Server | Clone the repo at GitHub.com |
Does it Have Snakes? is a Tomcat web application that shows the use of Elastic Beanstalk configuration files, Amazon RDS, JDBC, PostgreSQL, Servlets, JSPs, Simple Tag Support, Tag Files, Log4J, Bootstrap, and Jackson. The source code for this project includes a minimal build script that compiles the servlets and models into class files and packages the required files into a Web Archive that you can deploy to an Elastic Beanstalk environment. See the readme file in the project repository for full instructions. |
Locust Load Generator |
Java 8 |
Web Server |
Web application that you can use to load test another web application running in a different Elastic Beanstalk environment. Shows the use of
|
Download any of the sample applications and deploy it to Elastic Beanstalk by following these steps:
To launch an environment with a sample application (console)
Open the Elastic Beanstalk console
, and in the Regions list, select your AWS Region. -
In the navigation pane, choose Applications. Select an existing application in the list. You can also choose to create one, following the instructions in Managing applications .
-
On the application overview page, choose Create new environment.
The following image displays the application overview page.
This launches the Create environment wizard. The wizard provides a set of steps for you to create a new environment.
-
For Environment tier, choose the Web server environment or Worker environment environment tier. You can't change an environment's tier after creation.
Note
The .NET on Windows Server platform doesn't support the worker environment tier.
The Application information fields default, based on the application that you previously chose.
In the Environment information grouping the Environment name defaults, based on the application name. If you prefer a different environment name you can enter another value in the field. You can optionally enter a Domain name; otherwise Elastic Beanstalk autogenerates a value. You can also optionally enter an Environment description.
-
For Platform, select the platform and platform branch that match the language your application uses.
Note
Elastic Beanstalk supports multiple versions for most of the platforms that are listed. By default, the console selects the recommended version for the platform and platform branch you choose. If your application requires a different version, you can select it here. For information about supported platform versions, see Elastic Beanstalk supported platforms.
-
For Application code, you have some choices for launching a sample application.
-
To launch the default sample application without supplying the source code, choose Sample application. This action chooses the single page application that Elastic Beanstalk provides for the platform you previously selected.
-
If you downloaded a sample application from this guide or another source, do the following steps.
-
Select Upload your code.
-
Next choose Local file, then under Upload application, select Choose file.
-
Your computer's operating system will present you with an interface to select the local file that you downloaded. Select the source bundle file and continue.
-
-
-
For Presets, choose Single instance.
-
Choose Next.
-
The Configure service access page displays.
The following image illustrates the Configure service access page.
-
Choose a value from the Existing Service Roles dropdown.
-
(Optional) If you previously created an EC2 key pair, you can select it from the EC2 key pair field dropdown. You would use it to securely log in to the Amazon EC2 instance that Elastic Beanstalk provisions for your application. If you skip this step, you can always create and assign an EC2 key pair after the environment is created. For more information, see EC2 key pair.
-
Next, we'll focus on the EC2 instance profile dropdown list. The values displayed in this dropdown list may vary, depending on whether you account has previously created a new environment.
Choose one of the following items, based on the values displayed in your list.
-
If
aws-elasticbeanstalk-ec2-role
displays in the dropdown list, select it from the dropdown list. -
If another value displays in the list, and it’s the default EC2 instance profile intended for your environments, select it from the dropdown list.
-
If the EC2 instance profile dropdown list doesn't list any values, you'll need to create an instance profile.
Create an instance profile
To create an instance profile, we'll take a detour to another procedure on this same page. Go to the end of this procedure and expand the procedure that follows, Create IAM Role for EC2 instance profile.
Complete the steps in Create IAM Role for EC2 instance profile to create an IAM Role that you can subsequently select for the EC2 instance profile. Then return back to this step.
Now that you've created an IAM Role, and refreshed the list, it displays as a choice in the dropdown list. Select the IAM Role you just created from the EC2 instance profile dropdown list.
-
-
Choose Skip to Review on the Configure service access page.
This will select the default values for this step and skip the optional steps.
-
The Review page displays a summary of all your choices.
To further customize your environment, choose Edit next to the step that includes any items you want to configure. You can set the following options only during environment creation:
-
Environment name
-
Domain name
-
Platform version
-
Processor
-
VPC
-
Tier
You can change the following settings after environment creation, but they require new instances or other resources to be provisioned and can take a long time to apply:
-
Instance type, root volume, key pair, and AWS Identity and Access Management (IAM) role
-
Internal Amazon RDS database
-
Load balancer
For details on all available settings, see The create new environment wizard.
-
-
Choose Submit at the bottom of the page to initialize the creation of your new environment.
To create an IAM Role for EC2 instance profile selection
-
Choose View permission details. This displays under the EC2 instance profile dropdown list.
A modal window titled View instance profile permissions displays. This window lists the managed profiles that you'll need to attach to the new EC2 instance profile that you create. It also provides a link to launch the IAM console.
-
Choose the IAM console link displayed at the top of the window.
-
In the IAM console navigation pane, choose Roles.
-
Choose Create role.
-
Under Trusted entity type, choose AWS service.
-
Under Use case, choose EC2.
-
Choose Next.
-
Attach the appropriate managed policies. Scroll in the View instance profile permissions modal window to see the managed policies. The policies are also listed here:
-
AWSElasticBeanstalkWebTier
-
AWSElasticBeanstalkWorkerTier
-
AWSElasticBeanstalkMulticontainerDocker
-
-
Choose Next.
-
Enter a name for the role.
-
(Optional) Add tags to the role.
-
Choose Create role.
-
Return to the Elastic Beanstalk console window that is open.
-
Close the modal window View instance profile permissions.
Important
Do not close the browser page that displays the Elastic Beanstalk console.
-
Choose (refresh), next to the EC2 instance profile dropdown list.
This refreshes the dropdown list, so that the Role you just created will display in the dropdown list.
Next steps
After you have an environment running an application, you can deploy a new version of the application or a completely different application at any time. Deploying a new application version is very quick because it doesn't require provisioning or restarting EC2 instances.
After you've deployed a sample application or two and are ready to start developing and running Java applications locally, see the next section to set up a Java development environment with all of the tools and libraries that you will need.