Where to add .ebextensions in a WAR?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
For AWS Elastic Beanstalk, .ebextensions does not belong inside the WAR itself. It must sit at the root of the application source bundle that you upload to Elastic Beanstalk, alongside the WAR file, so the platform can read the configuration before deploying the Java application.
Put .ebextensions In The Source Bundle Root
Elastic Beanstalk processes configuration files from a top-level directory named .ebextensions. If you package a Java application as a WAR, the usual deployment artifact is not just the bare WAR when you need custom environment configuration. Instead, you upload a ZIP source bundle that contains:
- the WAR file
- the
.ebextensionsdirectory - optionally other deployment files such as platform hooks
A correct structure looks like this:
Save that as something like .ebextensions/01-env.config in the bundle root, not in WEB-INF and not inside the WAR.
Packaging The Bundle
If your application must be deployed as a WAR and you also need .ebextensions, create a deployment ZIP that wraps both pieces together.
Example command sequence:
That generated ZIP is what you upload to Elastic Beanstalk.
The exact WAR filename can vary by platform expectations and deployment style. Some Tomcat-based environments use ROOT.war to map the application to the root context.
Do Not Confuse App Files With Platform Files
A useful mental model is:
- WAR contents are for Tomcat and your Java application.
- '
.ebextensionsis for Elastic Beanstalk and the host environment.'
Once you separate those responsibilities, the packaging rule becomes obvious. The web server and the deployment platform are reading different layers of the bundle.
If you need application-level configuration, that belongs in the WAR. If you need environment-level deployment behavior, that belongs in .ebextensions at the bundle root.
Modern Alternatives
On newer Elastic Beanstalk platforms, you may also see .platform hooks used for certain customizations. That does not replace the location rule for .ebextensions; it just gives you another platform-level mechanism.
If your deployment setup is becoming complex, combining:
- a root-level
.ebextensions - optional
.platform - a clearly named WAR
is usually much easier to reason about than trying to hide everything inside the application archive.
Common Pitfalls
The most common mistake is placing .ebextensions inside the WAR file. Elastic Beanstalk will not process it there.
Another mistake is uploading only the WAR when the environment depends on custom config files. In that case the application may deploy, but instance setup steps will never run.
YAML formatting errors are also common. Even when the directory is in the right place, a malformed .config file can cause deployment failures or silently skipped behavior.
Finally, remember that .ebextensions belongs at the root of the uploaded source bundle, not one directory deeper inside a parent folder that was zipped by accident.
Summary
- '
.ebextensionsshould be placed at the root of the Elastic Beanstalk source bundle.' - Do not place it inside the WAR archive.
- When you need both a WAR and platform config, upload a ZIP bundle containing both.
- Use
.ebextensionsfor environment setup and WAR contents for application code. - Check both ZIP structure and YAML formatting if deployment behavior is missing.
Related reading
- Where to find Identity Pool Id in Cognito
- Which cloud based, scalable web service is best for DDOS prevention?
- Which Google Cloud Platform service is the easiest for running Tensorflow?
- Which is lower cost, Sagemaker or EC2?
- Which API Group in k8s
- Which jmx metric should be used to monitor the status of a connector in kafka connect?
- Where to get UTF-8 string literal in Java?
- Where to put Bean in Spring Boot?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.