Fork me on GitHub
#holy-lambda
<
2022-10-16
>
viesti11:10:49

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)

viesti11:10:45

idea was to have something more light weight than SAM for testing the build

viesti11:10:23

thinking that if there would be say a small http->lambda event proxy...

Karol Wójcik11:10:08

We can extend adapter to support this.

Karol Wójcik11:10:32

Believe me SAM is very light :D

Karol Wójcik11:10:56

It does exactly the same thing as you did with docker.

viesti11:10:53

yeah I'm probably doing couple of years backtracking :)

viesti06:10:08

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 🙂

Karol Wójcik06:10:55

At first SAM has to download the docker RIE images, therefore first time takes a while.

viesti06:10:13

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

viesti06:10:04

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

viesti06:10:08

--warm-containers EAGER
that was the switch to keep the container alive