问题
I'm trying to run a node js script on aws lambda that uses ffmpeg. To do this, I need to install ffmpeg on the machine itself.
I have looked trhough the documentation but I could not find how to connect to the machine that runs the lambda.
回答1:
You don't ever connect to the "machine" the Lambda is running on. There is no single machine the function runs on, and the function isn't even deployed until the first time it is called. The Lambda runs in one or more containers that are created and deleted on demand as requests come in. You have to include anything like ffmpeg in your Lambda's deployment package itself, so it will be there every time your function is deployed to a container.
Any binaries you include in your function's deployment package need to be built for Amazon Linux, which is the operating system Lambda runs on. You can either use an EC2 server to build the binaries or search for someone that has already packaged ffmpeg for Lambda and made it available.
回答2:
You can also find pre-compiled versions of ffmpeg
for aws-lambda
hosted by this cool dude, here: https://johnvansickle.com/ffmpeg/
(I went with the x86_64
build)
Tip: don't forget to set the correct +x
permissions for the binaries ffmpeg
and perhaps ffprobe
if needed.
回答3:
This works for me in Python:
- Get static build of ffmpeg from here, as already mentioned by @Xeroxoid
- Untar with
tar -zxvf ffmpeg-release-amd64-static.tar.xz
- Fetch file
ffmpeg
(and optionallyffprobe
) from folder. - Put bare ffmpeg file (without the subfolder) in the same folder as your lambda code.
cd
into this folder and zip withzip -r -X "../archive.zip" *
- Upload zipped file to AWS Lambda.
Set the correct filepath to ffmpeg like so:
FFMPEG_STATIC = "/var/task/ffmpeg"
import subprocess
subprocess.call([FFMPEG_STATIC, '-i', input_file, output_file])
来源:https://stackoverflow.com/questions/47044448/how-to-install-ffmpeg-on-aws-lambda-machine