Menu
AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Getting Started with Java on Elastic Beanstalk

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.

Samples

Name

Supported Configurations

Environment Type

Source

Description

Tomcat Default

Tomcat 8 with Java 8

Tomcat 7 with Java 7

Tomcat 7 with Java 6

Web Server

Worker

java-tomcat-v2.zip

Tomcat web application with a single page (index.jsp) configured to be displayed at the website root.

For worker environments, this sample includes a cron.yaml file that configures a scheduled task that calls scheduled.jsp once per minute. When scheduled.jsp is called, it writes to a log file at /tmp/sample-app.log. Finally, a configuration file is included in .ebextensions that copies the logs from /tmp/ to the locations read by Elastic Beanstalk when you request environment logs.

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.

Java SE Default

Java 8

Java 7

Web Server

java-se-jetty-gradle-v1.zip

Jetty SE application with Buildfile and Procfile configuration files. The Buildfile in this sample runs a Gradle command to build the application source on-instance.

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 8Web ServerClone 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 /api to the API running on localhost:5000.

Scorekeep also includes an xray branch that shows how to instrument a Java application for use with AWS X-Ray. It shows instrumentation of incoming HTTP requests with a servlet filter, automatic and manual AWS SDK client instrumentation, recorder configuration, and instrumentation of outgoing HTTP requests and SQL clients.

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 8Web ServerClone 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

Clone the repo at GitHub.com

Web application that you can use to load test another web application running in a different Elastic Beanstalk environment. Shows the use of Buildfile and Procfile files, DynamoDB, and Locust, an open source load testing tool.


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)

  1. Open the Elastic Beanstalk console.

  2. Choose an application or create a new one.

  3. In the upper right corner, choose Create New Environment from the Actions menu.

  4. Choose between Web server and Worker environment types. You cannot change an environment's tier after creation.

  5. For Platform, choose the platform that matches the language used by your application.

    Note

    Elastic Beanstalk supports multiple configurations for most platforms listed. By default, the console selects the latest version of the language, web container or framework supported by Elastic Beanstalk. If your application requires an older version, choose Configure more options below.

  6. For App code, choose Sample application.

  7. If you would like to further customize your environment, choose Configure more options. The following options can only be set during environment creation:

    • Environment name

    • Domain name

    • Platform configuration

    • VPC

    • Tier

    The following settings can be changed after environment creation, but require new instances or other resources to be provisioned and can take a long time to apply:

    • Instance type, root volume, key pair, and IAM role

    • Internal RDS database

    • Load balancer

    For details on all available settings, see The Create New Environment Wizard.

  8. Choose Create environment.

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.