是否可以在我的S3 lambda函数中创建一个文件?

时间:2017-03-31 16:53:35

标签: java amazon-web-services amazon-s3 lambda aws-lambda

我正在为AWS Lambda创建一个java函数,它从AWS S3引入一个文件,如下所示:

InputStream videoObjectStream = awsS3Video.getObjectContent();

我也在使用FFmpegFrameGrabber,这要求我在创建新的frameGrabber时指定文件路径,即:FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(filePath)

我正在尝试将InputStream转换为Lambda函数中的临时文件,但它不允许我创建文件。这是我将videoObjectStream转换为文件的代码:

byte[] inputBuffer = null;

        try {
            inputBuffer = IOUtils.toByteArray(videoObjectStream);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        System.out.println("The length of the byte array is " + inputBuffer.length);


        try {
            FileOutputStream videoOS = new FileOutputStream(videoDetails.get("videoFileKey"), false);
            videoOS.write(inputBuffer);
            videoOS.close();
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        File tempVideoFile = new File(videoDetails.get("videoFileKey"));

        if (tempVideoFile.exists()) {
            System.out.println("The file exists");
        } else {
            System.out.println("The file does not exist");
        }

然后,我得到以下堆栈跟踪,说这是一个只读文件系统:

java.io.FileNotFoundException: currentPath1490660005410.mp4 (Read-only file system)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
    at com.amazonaws.lambda.LambdaFunctionHandler.convertVideo(LambdaFunctionHandler.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at lambdainternal.EventHandlerLoader$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:456)
    at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:375)
    at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:1139)
    at lambdainternal.AWSLambda$2.call(AWSLambda.java:94)
    at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:290)
    at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:57)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94)

这有什么办法吗?我需要操纵视频数据,但不能先将其变成文件。欢迎任何建议。谢谢。

1 个答案:

答案 0 :(得分:14)

您必须在/tmp中创建文件。这是您在Lambda环境中唯一可以写入的位置。