This can be achieved by using the _JAVA_OPTIONS
environment variable, as described here.
The name of the environment variable may vary by JVM vendor, but currently elastic beanstalk uses OpenJDK, which respects _JAVA_OPTIONS
[webapp@ip-XXXXXXX ~]$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
You can set this environment variable only in the elastic beanstalk environment for which you wish to enable debugging. For example
_JAVA_OPTIONS=-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5001,suspend=n
Notes:
- the port you select must be open in one of the security groups assigned to your instances in that elastic beanstalk environment configuration.
- this works best if you are only running one instance in the elastic beanstalk, if you are running multiple instances then you won't know which instance to attach your debugger to.