java maven deployed in elastic bean stalk how to install 3rd party package -> wkhtmltopdf

1

I built a java app using the vaadin-flow framework with maven and java 17.

I already deployed the app in elastic bean stalk, connected it to a domain and its working properly.

Right now i want to install wkhtmltopdf for pdf creation on every ec2 instance for my app, it is my understanding that i need to use .ebextensions but how exactly will i describe this, what i want to run on the ec2 instance are the below 2 commands:

wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.aarch64.rpm

sudo yum install wkhtmltox-0.12.6-1.amazonlinux2.aarch64.rpm

As per my understanding i need to create a .ebextensions directory and add the .config file inside which will describe the commands i want to run, but can't figure out how to write or package this file so my question is, Is there any java maven example that uses a .ebextensions directory and deploys a 3rd party package to elastic bean stalk.

asked a year ago331 views
1 Answer
2
Accepted Answer

The following is an elegant way to manage an .ebextensions directory and build with maven using the maven-assembly-plugin:

  1. Create the .ebextensions directory under the root folder of your project (see screenshot) Project structure

  2. Create the following wkhtmltox.config file inside

files:  
  "/tmp/wkhtmltox.amazonlinux2.rpm": 
    mode: "000600"
    owner: root
    group: root
    source: https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm
commands:
  install_wkhtmltox: 
    command: sudo yum localinstall -y /tmp/wkhtmltox.amazonlinux2.rpm

Note:

  • adjust the URL according to the version and platform/cpu architecture
  • added parameter -y to automatically confirm the installation when executed programatically
  • switched from install to localinstall as we need return code 0 (success) also when the package is already installed (which will happen on the 2nd+ deployment)
  • syntax see [3]
  1. Extend pom.xml to use the maven-assembly-plugin to build a zip file which contains the applications jar file and the .ebextensions directory (without top level directory).
    </build>
      </plugins>
            ........
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <descriptors>
                        <descriptor>zip-with-ebextensions.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> 
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
  1. In the project root directory create the corresponding configuration file for the assembly plugin named zip-with-ebextensions.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.1 https://maven.apache.org/xsd/assembly-2.1.1.xsd">
  <id>with-ebextensions</id>
  <includeBaseDirectory>false</includeBaseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory></outputDirectory>
      <includes>
        <include>.ebextensions/**/*</include>
        <!-- <include>Procfile</include> -->
      </includes>
    </fileSet>
    <fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory></outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

Note: can be extended by including a Procfile (see [2]) if needed.

  1. Build your project with mvn package -Pproduction

Result: The target directory should contain a zip file named <app_name_with_version>-with-ebextensions.zip. The contents should look like: Enter image description here

When you login to the underlying EC2 instance, you can see that wkhtmltopdf was installed: Enter image description here

Final remark: The structure should also work, if you decide to deploy source code using e.g. the Elastic Beanstalk Command Line Interface (EB CLI), and build on the EC2 instance (see [1])

Related AWS Elastic Beanstalk documentation references:

  1. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html
  2. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-procfile.html
  3. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands
AWS
Norman
answered a year ago
  • Hi Norman, the above worked perfectly fine! thank you so much for this answer, couldn't have asked for a better answer!

  • Excellent !!!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions