awslabs / aws-lambda-web-adapter

Run web applications on AWS Lambda
Apache License 2.0
1.88k stars 114 forks source link

Assistance on running a Tomcat installation on AWS Lambda using the adapter #253

Closed InspectorGadget closed 1 year ago

InspectorGadget commented 1 year ago

Hi there,

I apologize if I am requesting for support at a wrong channel, or I am lacking of providing more context or showing effort. I'm currently learning how I could run Jasperreports on AWS Lambda with the adapter.

Context: Jasperreports is basically a Java app, but this image provided as base below has a Apache Tomcat layer on top of it. Although, I managed to find out where the war files are located (if it is helpful).

Problem: I am unable to understand the architecture or grasp the thought process on how I could implement this, as this is my first time working with a Java app. I am not sure if anyone here has achieved something similar to this.

What I have so far: :(

FROM bitnami/jasperreports:latest as builder

# Extract the war file
RUN unzip -q /opt/bitnami/jasperreports/jasperserver.war -d /tmp/jasperserver

# ...

Once again, I apologize if I'm lacking any context or sounding irrelevant - But I did try my best. I did checkout the examples made available within this repo to try to understand it, but still no luck. I would appreciate any little support provided to me.

bnusunny commented 1 year ago

Hi, no need to apologize. You are doing something no body did before.

bitnami/jasperreports is fully functional image, it will start Tomcat at 8080. I would try add adapter to the image like this.

FROM bitnami/jasperreports:latest
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.0 /lambda-adapter /opt/extensions/lambda-adapter

Build an image and create a Lambda function with all the necessary environment variables for testing.

I would expect it to fail through. Lambda's file system is readonly except /tmp and efs mount. Jasperreports probably will write logs or data to local file system. You need to change them to /tmp or an efs file system mount on the Lambda function.

It needs some time to get it right. Give it a try and post update here.

InspectorGadget commented 1 year ago

Hey @bnusunny ,

Thank you for your response. The approach above actually works, but my challenge would be how do I actually offload the writes to the writable folders of AWS Lambda.

Jasper writes to these folders: /opt/bitnami and /bitnami

bnusunny commented 1 year ago

You need to check Jasper's documents to figure out if there are configuration options to change the directories.

InspectorGadget commented 1 year ago

Hey @bnusunny ,

Fortunately, Bitnami has open-sourced the Dockerfiles for the Docker Images. (Ref)

However, prior to building everything and going through and fixing tons of errors to get it to run w/o errors. I found out that the Adapter is kinda stuck in the "Connecting" cycle, but running the custom built image locally - I could confirm that it works as intended. Please note that the Image will write to /mnt/jasper within the Container and /mnt/efs is attached to an Amazon EFS. Which I also believe that the Tomcat server is taking some time to boot up, and I have also passed in the Async Init env variable.

Attached with a screenshot from CW:

Screenshot 2023-07-16 at 6 31 10 PM
bnusunny commented 1 year ago

This is okay. At init phase, the adapter sends HTTP GET requests to the web app to check if it is ready.

InspectorGadget commented 1 year ago

Yeah @bnusunny. I managed to get it running on Lambda! 🥳

I would like to check something out of the context of this issue, I am getting this error while loading some dynamic content from an EFS AP attached to the Lambda.

prctl(PR_SET_DUMPABLE) failed (1: Operation not permitted)

I am not quite sure why this is happening.

bnusunny commented 1 year ago

Great to hear you make it working!

That is fine. The application is running as non-root user, and does not have the privilige to make that system call. You can ignore it.

raeveen commented 1 year ago

I am trying to load my entire WP Installation on EFS, with AP configured and the Runtime will refer to the mount directly (/mnt/root). In this case, it often comes out to this error.

When this error occurs, the Web page doesn't render properly. However, if I drop the entire WP inside /var/task - It just works fine without issues. Just that I wouldn't be able to upload files, or uodare WP itself.

bnusunny commented 1 year ago

@raeveen You are working on something different. You could check out this repo. It deploys a whole Wordpress site on Lambda, with several optimizations. I will close this issue now. Feel free to open a new issue in that repo.