Lambda powertool not working properly

0

Hello,

  • I configured an Eclipse project with AWS Toolkit installed, to use AWS Powertools package like specified at this link: https://awslabs.github.io/aws-lambda-powertools-java/

  • there was a Maven error in Eclipse Version: 2021-09 (4.21.0) Build id: 20210910-1417 that run on Java 11:
    Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.14.0:compile (execution: default, phase: process-classes)

  • the error was in pom.xml, at line with ERROR :

<build>
    <plugins>
        ...
        <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>aspectj-maven-plugin</artifactId>
             <version>1.14.0</version>
             <configuration>
                 <source>1.8</source>
                 <target>1.8</target>
                 <complianceLevel>1.8</complianceLevel>
                 <aspectLibraries>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-tracing</artifactId>
                     </aspectLibrary>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-logging</artifactId>
                     </aspectLibrary>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-metrics</artifactId>
                     </aspectLibrary>
                 </aspectLibraries>
             </configuration>
             <executions> <!--  ERROR at this line -->
                 <execution>
                     <goals>
                         <goal>compile</goal>
                     </goals>
                 </execution>
             </executions>
        </plugin>
        ...
    </plugins>
</build>
  • the error disappeared with new element (<pluginManagement>) added in below configuration:
<build>
<pluginManagement> <!--  this element fixed above ERROR -->
    <plugins>
        ...
        <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>aspectj-maven-plugin</artifactId>
             <version>1.14.0</version>
             <configuration>
                 <source>1.8</source>
                 <target>1.8</target>
                 <complianceLevel>1.8</complianceLevel>
                 <aspectLibraries>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-tracing</artifactId>
                     </aspectLibrary>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-logging</artifactId>
                     </aspectLibrary>
                     <aspectLibrary>
                         <groupId>software.amazon.lambda</groupId>
                         <artifactId>powertools-metrics</artifactId>
                     </aspectLibrary>
                 </aspectLibraries>
             </configuration>
             <executions>
                 <execution>
                     <goals>
                         <goal>compile</goal>
                     </goals>
                 </execution>
             </executions>
        </plugin>
        ...
    </plugins>
</pluginManagement> <!--  this element fixed above ERROR -->
</build>
  • but even so, seams that the plugin is not making weaving (does not generate the classes according to annotations)

  • below annotation does not log the event automatically:

    @Logging(logEvent = true,clearState = true)
    @Override
    public String handleRequest(S3Event event, Context context) {
  • If Eclipse has Version: 2018-12 (4.10.0) Build id: 20181214-0600 that ran on Java 8, the error from pom.xml does not appear, but the plugin is not making weaving also: there is no event logged automatically.

What configuration should I make, so that the event to be logged ?

Thank you,
Mihai

asked 2 years ago576 views
2 Answers
0

Try changing compiler version to 11 from 1.8.

<source>${maven.compiler.source}</source>

<target>${maven.compiler.target}</target>

<complianceLevel>${maven.compiler.target}</complianceLevel>

Compare your pom with below, which is a working examples. https://github.com/aws-samples/aws-lambda-powertools-examples/blob/main/java/CoreUtilities/Function/pom.xml

answered 2 years ago
  • Hello, Thank you for your indication.

    After making the changes, I could not make the deploy using AWS Toolkit, due to the fact that AWS Lambda function is not detected in the upload wizard during the upload into AWS Lambda. This happen because of the AWS Runtime that I have to change to Java 11 while AWS Toolkit detects only Java8.

    I made the build using Eclipse Maven plugin and the deploy using web console from Lambda service. This time the weaving worked, but it still does not log the event. Do you have a solution for this, please ? Please see below a stack trace with a good business-error, that shows that the weaving is done:

    java.lang.RuntimeException: AmazonDynamoDBv2 requestId: HGUSV59QMGHP9HP5V9VI5CHVH7VV4KQNSO5AEMVJF66Q9ASUAAJG for putItem has ExceptionCode: ConditionalCheckFailedException, with Lambda cause: attribute_not_exists(UserPictureNamePK) at com.amazonaws.lambda.mihai.rekonusers.dao.DynamoDao.putRecord(DynamoDao.java:83) at com.amazonaws.lambda.mihai.rekonusers.LambdaFunctionHandler.handleRequest_aroundBody0(LambdaFunctionHandler.java:37) at com.amazonaws.lambda.mihai.rekonusers.LambdaFunctionHandler$AjcClosure1.run(LambdaFunctionHandler.java:1) at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:257) at software.amazon.lambda.powertools.logging.internal.LambdaLoggingAspect.around(LambdaLoggingAspect.java:109) at com.amazonaws.lambda.mihai.rekonusers.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:27)

    Thank you, Mihai

0

The Lambda Power Tools Java is an open source project and with this type of use case it would be best to create an issue on the GitHub page so that the owners and contributors of the project would have visibility and also provide guidance or workaround as there may be other persons who have experienced the same.

https://github.com/awslabs/aws-lambda-powertools-java/issues

AWS
answered 2 years ago

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