0

I have a small AWS Lambda function written in Java with a Logback attached to it for sending out error log emails. The variables needed for the Logback appender (basic SMTP details) are loaded into the Logback.xml configuration appender SMTPAppender in the usual format of "${smtpPort}" etc. The variables are maintained through the Lambda Function Environment variable: key=JAVA_TOOL_OPTIONS, value=-DsmtpPort=587 -DsmtpHost=xyz. Here is the logback.xml configuration:

<configuration debug="true">

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{ISO8601} %-5p [%t] %c - %m%n</pattern>
        </encoder>
    </appender>

    <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
        <smtpPort>${smtpPort}</smtpPort>
        <STARTTLS>${startTls}</STARTTLS>
        <smtpHost>${smtpHost}</smtpHost>
        <username>${smtpUser}</username>
        <password>${smtpPassword}</password>
        <to>${logEmailTo}</to>
        <from>xxxx@xxxxxxxx.net</from>
        <subject>Error log [Scheduled Task Runner]</subject>
        <layout class="ch.qos.logback.classic.html.HTMLLayout">
            <pattern>%date%thread%level%logger%msg</pattern>
            <cssBuilder class="LambdaHandlers.util.ErrorEmailCssBuilder"/>
        </layout>
        <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
            <!-- send just 10 log entries per email -->
            <bufferSize>10</bufferSize>
        </cyclicBufferTracker>
    </appender>

    <logger name="org.apache.commons.httpclient" level="OFF"/>
    <logger name="httpclient.wire.header" level="OFF"/>
    <logger name="httpclient.wire.content" level="OFF"/>
    <logger name="httpclient.wire" level="OFF"/>
    <logger name="org.apache.http" level="OFF"/>
    <logger name="io.micrometer" level="INFO"/>
    <logger name="software.amazon.awssdk" level="OFF"/>
    <logger name="io.netty" level="OFF"/>
    <logger name="org.apache.catalina.realm" level="DEBUG"/>
    <logger name="org.apache.axis" level="INFO"/>

    <root level="debug">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="EMAIL"/>
    </root>
</configuration>

When the values are hardcoded in the logback.xml the email sending works as expected, however; after moving these to the JAVA_TOOL_OPTIONS bucket, the email stop working. The Lambda environment variables are correctly loaded on Lambda startup and can be accessed through the System.getProperty() in the Lambda context, providing the values from the environment variable.

BenK
  • 1

0 Answers0