Skip to content

feat: Support CRaC and priming of powertools batch#2590

Open
David-DAM wants to merge 1 commit into
aws-powertools:mainfrom
David-DAM:feature/support_crac_on_powertools_batch
Open

feat: Support CRaC and priming of powertools batch#2590
David-DAM wants to merge 1 commit into
aws-powertools:mainfrom
David-DAM:feature/support_crac_on_powertools_batch

Conversation

@David-DAM

Copy link
Copy Markdown
Contributor

Issue number: Closes #1998

Description of changes:

  • Added CRaC support in powertools-batch, following the guide and blogs mentioned on the ticket.
  • Added automatic priming for powertools-batch by preloading all the required classes, the list of classes is fetched from the JVM at compile time.

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sonarqubecloud

Copy link
Copy Markdown

@David-DAM

David-DAM commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @phipag I have tested the changes in my own AWS account, let me explain the process to validate that the steps are correct

  1. I have created a lambda function with only the dependency that I have changed, in this case powertools-batch and I have instantiate the class BatchMessageHandlerBuilder simulating the use
package com.davinchicoder;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import software.amazon.lambda.powertools.batch.BatchMessageHandlerBuilder;

import java.util.Map;

public class App implements RequestHandler<Map<String, String>, String> {


    static {
        System.out.println("Static initializer");
        new BatchMessageHandlerBuilder();
    }

    public App() {
        System.out.println("Constructor");
    }

    @Override
    public String handleRequest(Map<String, String> input, Context context) {
        context.getLogger().log("Handling request\n");
        return "OK";
    }
}
  1. I have enabled SnapStart for my lambda and when I published a new version of the lambda it triggers the primming call
  2. After that i can see the next logs
2026-07-25T12:32:00.889Z | INIT_START | Runtime Version: java:21.v77 | Runtime Version ARN: arn:aws:lambda:eu-west-3::runtime:29631c218b0f9e989981a51acd20da540e38940efec45dec7a8addf28ca349b1
2026-07-25T12:32:01.630Z | Static initializer
2026-07-25T12:32:01.731Z | Constructor
2026-07-25T12:32:03.433Z | [main] DEBUG software.amazon.lambda.powertools.batch.internal.XRayTraceEntityPropagator - X-Ray SDK not detected. Trace context propagation disabled
2026-07-25T12:32:06.295Z | [main] DEBUG software.amazon.lambda.powertools.common.internal.ClassPreLoader - SnapStart priming: preloaded 4102 class(es) from classesloaded.txt
2026-07-25T12:32:06.393Z | INIT_REPORT | Init Duration: 5504.55 ms

After that I suppose is working fine but just to let you know during the tests I got some errors before in the class ClassPreLoader, specifically in this method because it doesn't handle the LinkageError, in my case I was getting the NoClassDefFoundError, maybe because I got misconfigured my dependencies and I had to add some of them but just to let you know

private static boolean loadClassIfFound(String className) {
        try {
            Class.forName(className, true, ClassPreLoader.class.getClassLoader());
            return true;
        } catch (ClassNotFoundException e) {
            // No action is required if the class with given name cannot be found
            return false;
        }
    }

@David-DAM
David-DAM marked this pull request as ready for review July 25, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Priming for powertools-batch

1 participant