Interesting, I wanted to test locally the native-image build, but AWS SAM seemed a bit too much so wipped up a small docker image which has the lambda runtime interface emulator in it:
0% cat Dockerfile.test-native-image
FROM public.ecr.aws/lambda/provided:al2
# Copy custom runtime bootstrap
COPY .holy-lambda/build/bootstrap ${LAMBDA_RUNTIME_DIR}
# Copy function code
COPY .holy-lambda/build/output ${LAMBDA_TASK_ROOT}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "my.lambda" ]
and after building it, ran it with
docker run --rm -p 9000:8080 -e AWS_REGION=us-west-2 my-lambda:1
and since I use https://github.com/99designs/aws-vault#how-it-works for AWS access with a fake EC2 metadata service, it seems that the docker container is able to reach out to the fake local EC2 metadata server and fetch AWS credentials, provided that AWS_REGION was defined so code that hits AWS inside the lambda seems to work (well, I had only S3 presigning there, but that needs aws keys too)idea was to have something more light weight than SAM for testing the build
thinking that if there would be say a small http->lambda event proxy...
We can extend adapter to support this.
Believe me SAM is very light :D
ok 😄
It does exactly the same thing as you did with docker.
yeah I'm probably doing couple of years backtracking :)
Somehow though IIRC, on my machine the initial docker build took a while Also I guess I just wanted to dive down deep, see what are the bits that make these things 🙂
At first SAM has to download the docker RIE images, therefore first time takes a while.
yeah, I should try again, I think I might have been running just th the jar back then and sam by default restarted the jar with every reqeust which was dog-slow 😄 but then I found out switch for keeping the app alive
I guess my thoughts were in not needing a template.yml and to have http->lambda->http server that doesn't need a framework to work with, though this implies that the lambda does request routing by itself
--warm-containers EAGER
that was the switch to keep the container alive