Skip to content

Instantly share code, notes, and snippets.

@smithclay
Created July 28, 2017 02:59
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smithclay/7852bfdbf565ba6fe0601b0e2d01b56b to your computer and use it in GitHub Desktop.
Save smithclay/7852bfdbf565ba6fe0601b0e2d01b56b 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).

@diplodata
Copy link

I can't find the AWS Lambda AMI. Is it region specific?

@DuttaPritam
Copy link

Hi, need one help in terms of java code. I have design a framework with lambda function with code java where I am putting the chrome browser 62 headless inside the project and uploading the same in the project. But, the problem I am facing is chrome driver is not been found.

  1. If you please let me know for the windows configuration how to set the command ldd and the environment variable LD_LINKER_PATH.
  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'))

If you please reply.

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