-
[AWS Lambda]IMAGEIO_FFMPEG_EXE error when using MoviepyAWS/Serverless 2020. 1. 2. 18:29
(I'm sorry for my poor english skill, but I'll do the best to explain detaily!)
Problem
When using Moviepy library in AWS Lambda, it can occur error,
→ 'Permission denied accessing folder with IMAGEIO_FFMPEG_EXE file'.
I was so mad for this, but finally I got a solution!
Cause
Before enter solution, you should know one information about AWS Lambda,
AWS Lambda only allows access permission path '/tmp/'.
So the problem occurs because of access to specific path which have ffmpeg file, not in /tmp!
Solution
Step1
First of all, you should install Library(Apply to most library!!) in AWS Lambda OS.
Please refer to this: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
docs.aws.amazon.com
If you just install the library in macOS or Windows, the library will be not executed in AWS Lambda.
Because OS in AWS Lambda is AWS Linux. (Not same normal Linux!!)
So, you should create instance in AWS EC2 referring above link and install the library you want.
▶ Or you can use AWS linux image in Docker.
Step2
Secondly, you should find binary file named 'ffmpeg-linux64-v4.1'.
(I think it's name depends on libraries version.)
Maybe It's in path '{Path for Moviepy Library}/imageio_ffmpeg/binaries/'.
Then upload that file to S3 bucket which you have.
(To import Library to AWS Lambda with S3 bucket.)
Step3
Almost done!
You should download 'ffmpeg-linux64-v4.1' file to '/tmp/'.
(at S3 bucket) (at Lambda)
Then you should set path of your system environment variable, 'IMAGEIO_FFMPEG_EXE'.
So code like this!
import boto3 from moviepy.editor import * import os def lambda_handler(event, context): s3 = boto3.client('s3') os.environ['IMAGEIO_FFMPEG_EXE'] = '/tmp' s3.download_file('bylivetest', 'ffmpeg-linux64-v4.1', '/tmp/ffmpeg-linux64-v4.1') # your bucket name file to downliad path to download
Because we use '/tmp/' path safely and AWS Lambda OS can catch environment variable 'IMAGEIO_FFMPEG_EXE',
now you can use Moviepy library in AWS Lambda!!
Thank you for reading!