title: How to write a Dockerfile for an AWS Lambda function deployed as a container?
body: <p>I've been writing an application on AWS that consists of several Rust lambdas. One of those lambdas has to have access to a bunch of external dependencies and therefore needs to be Dockerized. As I understand, the official AWS Lambda runtime for Rust runs within the lambda's binary and shouldn't need any special setup or exposing of ports.
  My Dockerfile is as follows:</p>
  <pre><code># building omitted
  FROM alpine:latest AS runner
  WORKDIR /root/
  COPY target/x86_64-unknown-linux-musl/release/my-lambda ./my-lambda
  CMD [ &quot;/root/my-lambda&quot; ]
  </code></pre>
  <p>The image then gets built and pushed to an Amazon ECR registry my Lambda is configured to get its code from.
  The logs I get when invoking the function with any test data in the AWS console are:</p>
  <pre><code>IMAGE   Launch error: fork/exec /root/my-lambda: permission denied  Entrypoint: []  Cmd: [/root/my-lambda]  WorkingDir: [/root/]
  START RequestId:  (...) Version: $LATEST
  IMAGE   Launch error: fork/exec /root/my-lambda: permission denied  Entrypoint: []  Cmd: [/root/my-lambda]  WorkingDir: [/root/]
  END RequestId:  (...)
  REPORT RequestId:  (...)    Duration: 59.75 ms  Billed Duration: 60 ms  Memory Size: 128 MB Max Memory Used: 5 MB   
  RequestId: (...) Error: fork/exec /root/my-lambda: permission denied
  Runtime.InvalidEntrypoint
  </code></pre>
  <pre><code>{
    &quot;errorMessage&quot;: &quot;RequestId: (...) Error: fork/exec /root/my-lambda: permission denied&quot;,
    &quot;errorType&quot;: &quot;Runtime.InvalidEntrypoint&quot;
  }
  </code></pre>
  <p>I know the problem is not with:</p>
  <ul>
  <li>the <code>my-lambda</code> executable file's permissions (anyone can execute it, I've tried chmod -R 777 for good measure too)</li>
  <li>the availability of libc (I specifically compiled for the musl target, as is best practice for Rust lambdas due to the Rust stdlib almost always linking to a newer glibc than Amazon Linux has)</li>
  <li>whether or not the Docker image even runs - if I try to run the image locally, my lambda runs and crashes on not finding the AWS_LAMBDA_RUNTIME_API env var or other variables lambdas depend on, as expected</li>
  <li>the executable's naming or if it's invoked with a relative path - naming it <code>bootstrap</code> in line with lambda convention and finishing with <code>CMD [&quot;./bootstrap&quot;]</code> did not help</li>
  </ul>
  <p>I've also tried using an <code>ENTRYPOINT</code> rather than a <code>CMD</code> in the dockerfile, as well as providing a placeholder <code>CMD</code> like <code>doesnt.matter</code>.</p>
  <p>Googling around for a solution has only turned up Rust lambda builder images and similar-looking but unrelated errors for Golang.</p>