Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xenophonf/c4e04f7fd464b80f9690b8d23c90b4fa to your computer and use it in GitHub Desktop.
Save xenophonf/c4e04f7fd464b80f9690b8d23c90b4fa to your computer and use it in GitHub Desktop.
Recipe for Getting Strange Binaries Running in AWS Lambda

Recipe for running strange binaries in AWS Lambda

In general, the command ldd and the environment variable LD_LINKER_PATH is your best friend when running new, untested binaries in Lambda. My process (which I want to get around to automating one day, maybe using Packer), goes like this:

  1. Run an EC2 instance with the official AWS Lambda AMI.
  2. Get binary you want to run in AWS Lambda running on the instance (either by installing from a package manager or compiling). 
  3. Run ldd -v ./the-binary. Note all of the shared libraries it requires. You’ll need to remember these.
  4. Copy the binary to your local machine. Upload the binary with your AWS Lambda function code that runs the ldd command inside the handler function using the process execution library from your language of choice. In node, this works just fine: console.log(require('child_process').execSync('ldd -v ./the-binary'))
  5. Note any shared libraries that are missing in the function output. Copy those over from the EC2 instance to a directory that exists in the AWS Lambda environment’s LD_LINKER_PATH — in this case, that includes any directory named lib/ in your function.
  6. Run ldd in the function action. Note anything that says “not found” until everything is copied over to the function. Repeat.
  7. Finally, try running the function itself and watch the output: console.log(require('child_process').execSync('./the-binary'))

Sometimes, it works fine. Sometimes, there are weird errors. Sometimes, you realize the binary needs a permission that isn’t allowed (sadly, this includes some interesting stuff like ptrace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment