SpringBoot fails to deploy after adding .ebextensions for ngingx SSL -[An error occurred during execution of command [app-deploy]]

Viewed 2559

I have a SpringBoot app that deploys just fine to AWS Beanstalk, and the default nginx proxy works, allowing me to connect via port 80.

Following the instructions here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-singleinstance.html, and verifying with another of my projects that works with this exact config, Beanstalk fails to deploy the app with error:

2020/05/29 01:27:56.418780 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle

The contents of my war file are as such:

app.war
    -.ebextensions
        -nginx/conf.d/https.conf
        -https-instance-single.config
        -https-instance.config
    -web-inf/

My config files pass as valid yaml files. (These files are identical to those in the AWS doc, and those that work in other project on mine.)

I am using a single instance, with port 443 set open.

These are the errors reported throughout the various log files:

----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2020/05/29 01:37:53.054366 [ERROR] /usr/bin/id: healthd: no such user
...
2020/05/29 01:37:53.254965 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/healthd.service to /etc/systemd/system/healthd.service.
...
2020/05/29 01:37:53.732794 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/cfn-hup.service to /etc/systemd/system/cfn-hup.service.


----------------------------------------
/var/log/cfn-hup.log
----------------------------------------
ReadTimeout: HTTPSConnectionPool(host='sqs.us-east-1.amazonaws.com', port=443): Read timed out. (read timeout=23)
5 Answers

Taking count @Dean Wookey's answer for Java 11, I have successfully deployed Spring Boot application jar along with .ebextensions folder. I just added maven antrun plug to my maven build configurations and for output I am receiving .zip file, which contains .ebextensions folder and spring Boot .jar file at the same level. Just deploying this final zip file to AWS UI Console.

The following is the maven antrun plugin configuration

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

Issue with Java and Linux version

enter image description here

If you are using Java 8 and Linux 2.10.9 code will work and override ngingx configuration but if you choose Corretto 11 and Linux 2.2.3 get following error.

Error: there is no Procfile and no .jar file at root level of your source bundle

Create new environment with Java 8 and deploy app again will resolve issue.

Instead of changing to java 8 as described in vaquar khan's answer, an alternative is to package your source jar inside a zip that also contains the .ebextensions folder.

In other words:

source.zip
    -.ebextensions
        -nginx/conf.d/https.conf
        -https-instance-single.config
        -https-instance.config
    -web-inf/
    -app.war

If you look at the latest documentation https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html, you'll see that the nginx config now goes in the .platform folder instead, so your structure would be:

source.zip
    -.ebextensions
        -https-instance-single.config
        -https-instance.config
    -.platform
        -nginx/conf.d/https.conf
    -web-inf/
    -app.war

After following vaquar's answer above, also change the 'buildspec.yml' file to have the correct java version. E.g: runtime-versions: java: corretto8 # previously this was openjdk8

Should work.

It is still possible to use .ebextensions within your war file.

Add following to your pom.xml in the <build><plugins> section:

<build>
<plugins>
...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-resource-ebextensions</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>add-resource</goal>
            </goals>
            <configuration>
                <resources>
                    <resource>
                        <directory>${basedir}/.ebextensions</directory>
                        <targetPath>.ebextensions</targetPath>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
...
</plugins>
</build>

This will copy .ebextensions folder to WEB-INF/classes folder. There AWS picks it up while starting and applies scripts from there.

Related