Lambda: Java Performance when reading S3 Json Data

0

Hi there,

I am new to the Java SDK and used Node before. I noticed, that my lambda function, which reads JSON from a S3 Bucket, processes it and saves it back, is very inefficient. I made some measurements and noticed, that the processing is really quick, but fetching the data and converting it to a object, takes so much time. Node was much more efficient in this case.

Do you have any idea, how I could make this more efficient? I used Jackson.

        S3Client s3Client = S3Client.builder()
            .region(Region.EU_WEST_1)
            .build();

        GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                .bucket("my-resource-bucket")
                .key("my-data.json")
                .build();

        JsonNode rootNode;
        try (InputStream inputStream = s3Client.getObject(getObjectRequest, ResponseTransformer.toInputStream())) {
            ObjectMapper objectMapper = new ObjectMapper();
            rootNode = objectMapper.readTree(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        doProcessing(rootNode);

        PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                .bucket("my-outbut-bucket")
                .key("my-data-processed.json")
                .build();

        s3Client.putObject(putObjectRequest, RequestBody.fromBytes(rootNode.toPrettyString().getBytes()));

I am pretty sure, I did something very not efficient. Thank you for any help!

No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions