Serverless:  Create Audiowaveform Layer in AWS Lambda

If you have access to your own server, installing any software will be easy-peasy, but how to install and use custom binary/library in your AWS Lambda?

In my case, i will need to install and use audiowaveform library (https://github.com/bbc/audiowaveform) in my AWS Lambda function.

Here's my documentation for that. 

1. Build audiowaveform library
First, we will need to make sure that our binary are running in AWS Lambda Linux runtime, so we will need to build the audiowaveform to run in AWS Lambda Linux.

Fortunately, someone already create that, so we can just run some code to compile a static library we need.

Please note that you will need to install docker and nodejs to run the command below

git clone git@github.com:reelcrafter/audiotool-builders.git audiotools
cd audiotools/audiowaveform
yarn build
yarn install

Behind the scene, when we run yarn build  (please note that it will take a lot of times) : 

1. Build and run amazonlinux instance in your Docker
2. Install all dependencies to build audiowaveform inside amazonlinux
3. Build audiowaveform static binary for amazonlinux

And yarn install will copy your audiowaveform binary to audiotools/audiowaveform/bin folder.



Zip that audiowaveform file, so we will have audiowaveform.zip

2. Create AWS Layer 
Go to AWS Lambda Layer Page -> Create Layer



Fill in the Name field, choose audiowaveform.zip on Upload button.

For Compatible architecure choose x86_64, since we use that architecture by default when building audiowaveform static library. 

For Compatible runtimes you can use language that you will use in AWS Lambda functions, in my case i will use Node.js, so i will choose Node.js

Click Create, you will get the following screen



3. ARN Info

After create layer, we will get arn info, something like :
arn:aws:lambda:us-east-1:blablabla:layer:audiowaveform:2

That's all! Next, we will use that audiowaveform layer (using the arn-info) in our AWS Lambda function.

Comments