Java – can I create a file in my S3 lambda function?

I am creating a Java function for AWS lambda, which imports a file from AWS S3, as shown below:

InputStream videoObjectStream = awsS3Video. getObjectContent();

I am also using ffmpegframegrabber, which requires me to specify a file path when creating a new framegrabber, that is, ffmpegframegrabber framegrabber = new ffmpegframegrabber (filepath)

I tried to convert InputStream to a temporary file in my lambda function, but it doesn't allow me to create a file This is my code for converting videoobjectstream to a file:

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");
        }

Then I get the following stack trace, saying that this is a read-only file system:

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)

Is there a solution? I need to manipulate the video data, but I can't turn it into a file first Any suggestions are welcome thank you.

Solution

You must create the file in / tmp This is the only place you can write in the lambda environment

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>