Deploy non-JS binary files with functions

In my function I’m calling an API that requires a specific SSL certificate while making the calls. The API vendor issues me a PFX file which I should read in my function and then pass in to Axios.

If PFX was a text file, I would’ve used the Environment variables in Netlify UI and accessed them in the functions via process.env, as implemented in https://github.com/depadiernos/token-hider-inator. However, PFX is a binary file.

How can I deploy a binary file along with my function (in a way that the function has access to it)?

Hi @jirayr, have you tried zipping it in with your function? Also note that you can base64 encode the binary as well.

@futuregerald

I have similar issue. I am using ffpmpeg-static(https://www.npmjs.com/package/ffmpeg-static) and I guess I also need to zip it.

I looked around for examples or an article/tutorial or a boilerplate which shows how to use zip-it-and-ship-it, but could not find any.

Would appreciate your help/guidance on this. Thanks in advance.

Note: I see from my build notes that zip is already in action! I use cloudinary.

11:07:07 AM: Prepping functions with zip-it-and-ship-it 0.3.1
11:07:13 AM: [ { path: ‘/tmp/zisi-5dd773d407f7170008275abd/cloudinaryConfig.zip’,
11:07:13 AM: runtime: ‘js’ },

So I guess I am close.

More details:

“scripts” from package.json:
“scripts”: {
“prebuild”: "npm i @ffmpeg-installer/linux-x64 ",
“build”: "netlify-lambda build express ",
“lambda-build”: “netlify-lambda build express”,
“start”: “nodemon -r esm server-local.js -e ./env”
},

“dependencies”: {
@ffmpeg-installer/ffmpeg”: “^1.0.20”,
@ffprobe-installer/ffprobe”: “^1.0.12”,
“cloudinary”: “^1.16.0”,
“connect-busboy”: “0.0.2”,
“cors”: “^2.8.5”,
“datauri”: “^2.0.0”,
“dotenv”: “^8.2.0”,
“esm”: “^3.2.25”,
“ffmpeg-static”: “^2.7.0”,
“ffprobe-static”: “^3.0.0”,
“fluent-ffmpeg”: “^2.1.2”,
“multer”: “^1.4.2”,
“promisify”: “0.0.3”
},
“devDependencies”: {
“body-parser”: “^1.19.0”,
“express”: “^4.17.1”,
“netlify-lambda”: “^1.6.3”,
“nodemon”: “^1.19.2”,
“serverless-http”: “^2.3.0”
}

Boilerplate used:

netlify.toml

[build]
command = “npm install && npm run build”
functions = “functions”
[build.environment]
FLUENTFFMPEG_COV = “”

Hi, @instantwpuserwin. Which Netlify site is this for? Being able to examine the sire would help us to gather more information for troubleshooting.

A link to the site in the Netlify UI (app.netlify.com) or the API ID (not the API key - the ID) for this site would help us to uniquely identify it.

Hey Luke:

Appreciate your reply.

Here’s API Id: e016b370-bea5-43ca-b31a-86cd1b6f198c

More details:
I am printing static path of the binary and it shows path to the binary as (function log):
/bin/linux/x64/ffmpeg
But when i try to call this binary, I get “Error: spawn ./ffmpeg ENOENT”
(server.js)

Thanks

@instantwpuserwin, we have zip it and ship it in the build environment already, and it auto-runs on all Javascript functions in your functions directory. You can read more about how it works in its repo: https://github.com/netlify/zip-it-and-ship-it

Does the function work for you when you test it locally? have you checked the repo to see if others are having trouble running it in lambda functions?

Hey

In my local it works very well. (Windows 10).

“Have you checked the repo to see if others are having trouble running it in lambda functions?”

I am sorry. Did not understand what you meant ?

Appreciate your help and patience.

I think Gerald was suggesting you look through the https://github.com/netlify/zip-it-and-ship-it/issues repo issues to see if anyone else has experienced the same trouble. Then, if no one has, you could file the issue there in the repo.