Reputation: 11
I'd like to deploy Karate API mock server v1.5.1 to my AWS Lambda. Given the karate.jar file is more than 50MB, I can't deploy it directly to Lambda. Deploy it via a container image looks like a good approach in my case.
I have created a dockerFile for my karate API mock server v1.5.1, as shown below
FROM public.ecr.aws/lambda/java:21-arm64
COPY ./Request /karate/Request
COPY ./Response /karate/Response
COPY karate.jar /karate/karate.jar
COPY mockserver.feature /karate/mockserver.feature
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "/karate/karate.jar", "-m", "/karate/mockserver.feature", "-p", "8081"]
It can generate a docker image and the relevant docker container works fine in my local machine.
After I created an AWS Lambda with an arm64 architecture, and pushed my docker image to the AWS ECR, and deployed my lambda via my docker image from the ECR, I started to run a quick test on this Lambda, but I've got below error:
15:34:21.132 [main] INFO com.intuit.karate - Karate version: 1.5.1
2025-01-27T15:34:24.197Z
15:34:24.197 [main] INFO com.intuit.karate - mock server initialized: ../../karate/mockserver.feature
2025-01-27T15:34:24.793Z
15:34:24.793 [main] DEBUG com.intuit.karate.http.HttpServer - server started: 169.254.49.101:8081
2025-01-27T15:34:30.249Z
INIT_REPORT Init Duration: 10009.08 ms Phase: init Status: timeout
2025-01-27T15:34:30.914Z
15:34:30.911 [main] INFO com.intuit.karate - Karate version: 1.5.1
2025-01-27T15:34:32.761Z
15:34:32.761 [main] INFO com.intuit.karate - mock server initialized: ../../karate/mockserver.feature
2025-01-27T15:34:32.912Z
15:34:32.912 [main] DEBUG com.intuit.karate.http.HttpServer - server started: 169.254.49.101:8081
2025-01-27T15:39:30.334Z
INIT_REPORT Init Duration: 300059.50 ms Phase: invoke Status: timeout
2025-01-27T15:39:30.334Z
START RequestId: e4bb592d-5042-4e70-900e-e1c82b8741f1 Version: $LATEST
2025-01-27T15:39:30.342Z
2025-01-27T15:39:30.340Z e4bb592d-5042-4e70-900e-e1c82b8741f1 Task timed out after 300.07 seconds
2025-01-27T15:39:30.342Z
END RequestId: e4bb592d-5042-4e70-900e-e1c82b8741f1
So I wonder what's missing in my steps that caused the karate mock server not to pass the init and invoke stages and gave me timeout error.
Upvotes: 1
Views: 17
Reputation: 58058
The Karate mock server is a Java process that starts and waits for incoming connections. So to the Lambda runtime it looks like it has hung.
I think a normal Docker container running on EC2 or ECS is the best approach. In theory you could connect AWS API gateway to Lambda then write some Java code to convert the incoming request to a com.intuit.karate.http.Request
object and pass it to some internal Karate classes and achieve a "true" Lambda backed mock. But that defeats the whole point of a mock, which is to do the least amount of work in order to spin up an HTTP server for testing.
So my recommendation is to stick to a normal container that you have to shut down after you are done.
By the way using Lambda "layers" is a way to overcome the JAR size limitation.
Upvotes: 0