anmonteiro / aws-lambda-ocaml-runtime

An OCaml custom runtime for AWS Lambda and Vercel
BSD 3-Clause "New" or "Revised" License
207 stars 8 forks source link

How to run the basic example with only dune, no docker #64

Open dangdennis opened 2 years ago

dangdennis commented 2 years ago

Hi @anmonteiro

Do you have an idea as to why I receive this error from my basic lambda? I've changed the build.sh to build with only dune without docker. Although it's likely my build script is incorrect now and is the root issue of this, the basic example doesn't work as-is because it lacks the esy.json and esy.lock file that the dockerfile expects.

{
  "errorMessage": "RequestId: 5489ab76-43af-4303-9ec8-9984e5ae7c44 Error: fork/exec /var/task/bootstrap: exec format error",
  "errorType": "Runtime.InvalidEntrypoint"
}
#!/usr/bin/env sh

set -eo pipefail

root_path=$PWD

# Start in examples/basic/ even if run from root directory
cd "$(dirname "$0")"

rm -rf bootstrap
# possible that this is the issue because i left out --profile=static
dune build basic.exe
mv ../../_build/default/examples/basic/basic.exe ./bootstrap
zip -j ./ocaml.zip bootstrap

cd $root_path
anmonteiro commented 2 years ago
  1. The AWS Lambda environment expects to run a x86 ELF binary.
  2. In most cases it's better to build a statically linked binary to avoid having to guess where Amazon Linux has things like glibc, openssl, etc.

So, re 1. Did you compile something on macOS to be executed on Linux?

And if you're on Linux, re 2. Did you ship a dynamically linked executable that can't find its libraries at runtime?

dangdennis commented 2 years ago

Ah this is indeed why I have to use the dockerfile for the linux build. I'm compiling on a m1 arm macbook.

Let's see if I hit 2 once I reinstate the use of docker. I'll use esy too then.

dangdennis commented 2 years ago

Logging my adventures here. Back to my original error with esy: As we can see here, building the docker image causes an error immediately on the lack of esy.json and esy.lock. We expect these files to exist because we write esy.json and the result of running esy should have generated esy.lock.

 => CACHED [esy  9/18] RUN echo ' {  "name": "package-base",   "dependencies": {     "ocaml": "4.9.0",     "@opam/dune": "*"   0.0s
 => CACHED [esy 10/18] RUN esy                                                                                                 0.0s
 => ERROR [esy 11/18] COPY esy.json esy.json                                                                                   0.0s
 => ERROR [esy 12/18] COPY esy.lock esy.lock    
anmonteiro commented 2 years ago

do you have a .dockerignore?

anmonteiro commented 2 years ago

Those files need to exist locally. The examples/basic directory doesn't include them

dangdennis commented 2 years ago

I see only the dockerignore you’ve created.

If by locally, do you mean locally inside the docker image? Or within my own current file system. But often when I do a COPY, yes it’s from my own local file system into the image.

I’ll continue again tomorrow 🫠