11

I'm trying to add an .ebextensions folder to the root level of my jar to be deployed to AWS elastic beanstalk.

My folder structure is:

main:
--src
--resources
  --.ebextensions

When I build the jar my .ebextensions gets placed on the classpath of my target and therefore is not picked up by Elastic Beanstalk on deploy.

Pom.xml

<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
           <fork>true</fork>
           <addResources>false</addResources>
     </configuration>
</plugin>

How can I build so that ebextensions is picked up by ELB?

moffeltje
  • 4,521
  • 4
  • 33
  • 57
s.pike
  • 389
  • 3
  • 8
  • You'll probably be interested in [this Spring Boot issue](https://github.com/spring-projects/spring-boot/issues/6626). – Andy Wilkinson Mar 09 '17 at 20:06
  • 1
    Actually, are you sure you want the file in the root of the jar? [The documentation](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html) suggests that `.ebextensions` should sit next to your jar file in your application source bundle. – Andy Wilkinson Mar 09 '17 at 20:09
  • Create a source bundle: https://medium.com/@autumn.bom/deploying-spring-boot-jar-application-on-beanstalk-java-se-platform-45d8d04608ae – jaco0646 Jul 10 '18 at 14:06
  • From the document referenced above: "Location – Place all of your configuration files in a single folder, named .ebextensions, in the root of your source bundle. Folders starting with a dot can be hidden by file browsers, so make sure that the folder is added when you create your source bundle." – Tony Edwards Sep 03 '20 at 19:29
  • I can confirm that it needs to be in the root of the jar. I state this after days of working with AWS support. But I will state that this is for Java8 and Tomcat running on Amazon Linux 1. Linux 2 is different. – Tony Edwards Sep 10 '20 at 18:09

5 Answers5

26

This works for me, is the cleanest way (in maven) I found to solve this:

Add .ebextensions in the root of your project and add this snippet at the end in the plugins section:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>prepare</id>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <unzip src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.directory}/${project.build.finalName}" />
                            <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
                                <fileset dir="./" includes=".ebextensions/**"/>
                            </copy>
                            <zip compress="false" destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.build.finalName}"/>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

This plugin use ant to unzip the final jar generated by spring boot, copy the .ebextensions in the root and zip (jar) again with the same name. Tested and working in production :)

Works with Spring 1.5.3.RELEASE

Javier Arnáiz
  • 710
  • 8
  • 11
  • Very useful +1. By chance do you know an updated plugin that does the same? Last code from `maven-antrun-plugin` is from 2014. – Federico Piazza Nov 07 '18 at 22:51
  • Very handy! I prefer to name the source folder without a leading period, so that my OS doesn't hide it, and to include AWS in the path. Somewthing like: `src/main/aws/ebextensions`. It gets renamed to `.ebextensions` when I copy it into the zip. – Bampfer May 23 '19 at 22:20
  • Some might find this a better alternative: https://stackoverflow.com/a/64911750/3112373 – amucunguzi Jan 06 '21 at 09:49
  • This sets the folder name as "ebextensions", not ".ebextensions" – CuriousCoder Aug 04 '21 at 23:35
2

I was having the same problems, moving .ebextensions next to the jar as Andy suggested worked for me when I combined it with directly adding a .conf file to the desired directory as suggested here:

https://stackoverflow.com/a/41011160/7686379

Community
  • 1
  • 1
Evan Stitt
  • 21
  • 3
1

For those of you using Gradle, here is what needs to be added to your build.gradle in order to add the .ebextensions stuff to the root of the jar.

It assumes that the .ebextensions directory and contents are in the root of your project.

Normal Java app:

jar {
    from(".") {
        include ".ebextensions/**"
    }
}

Spring Boot app:

bootJar {
    from(".") {
        include ".ebextensions/**"
    }
}

The Spring Boot case is slightly different to the normal Java case because with Spring Boot it is the Spring Boot Gradle plugin that actually constructs the jar - and it uses a special "bootJar" task in place of the standard Java plugin "jar" task.

I think that for Maven builds, Javier's answer is the cleanest way to go. For me, this illustrates the flexibility of Gradle over Maven when modifying "standard" builds.

jadc
  • 195
  • 2
  • 8
0

For all of you who might struggle with this. Have a directory in the root of your project that looks like this: .ebextentions/nginx/conf.d/proxy.conf In the proxy.conf file you place this client_max_body_size 50M; which does exactly that. Now when you upload your project to elastic beanstalk, what you do is you make a zipped folder, and then you copy your target folder and the .ebextensions directory into it this is called a source bundle. Now you can upload the zipped folder(bundle) to elastic beanstalk.

benja
  • 1
0

Here is how i did it:
Ran mvn install which generated app-0.0.1-SNAPSHOT.jar
After that i have created .ebextensions/nginx/conf.d/proxy.conf on root project path which has client_max_body_size 25M; - in my case was to increase maximum upload size.
Using Github Actions and ubuntu-latest for the runner - the zip command is supported out of the box and i did it with this command

cp target/app-0.0.1-SNAPSHOT.jar . && zip -r app-new.zip .ebextensions/ app-0.0.1-SNAPSHOT.jar

Basically the app-new.zip is the file that i am uploading to ElasticBeanstalk

alext
  • 678
  • 1
  • 11
  • 25