5

I am trying to access SSM parameter store from lambda. I have noticed major difference in performance when parameter is fetched from lambda based on Java AWS SDK Vs lambda based on NodeJS AWS SDK.

  • For java based lambda - to retrieve first parameter it takes around 5-10 seconds
  • For NodeJS based lambda - to retrieve first parameter it takes around 0.5-1 seconds

Sample code for java based lambda to fetch parameter:

import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult;

public class SSMClientUtil {

    private static AWSSimpleSystemsManagement ssm = AWSSimpleSystemsManagementClientBuilder.defaultClient();

    public static String getParameter(final String parameterName) {
        final long startTime = System.currentTimeMillis();
        final GetParameterRequest request = new GetParameterRequest();
        request.setName(parameterName);
        request.setWithDecryption(true);
        final GetParameterResult parameterResult = ssm.getParameter(request);
        System.out.println("GetParameterResult for parameter: " + parameterName + " Time : " + (System.currentTimeMillis() - startTime) + " -> " + parameterResult);
        return parameterResult.getParameter().getValue();
    }

}

Sample code for NodeJS based lambda to fetch parameter:

const AWS_SDK = require("aws-sdk");
ssmClient = new AWS_SDK.SSM();
var parameterPromise =  await ssmClient.getParameter(params).promise();
console.log('parameterPromise: ' + JSON.stringify(parameterPromise));
return parameterPromise.Parameter.Value;
  1. Is it expected behavior? Why java based lambda takes almost 10 times more time than NodeJS to retrieve parameter?
  2. While packaging lambda in NodeJS AWS SDK is not required, but for Java it's mandatory as it's required at compile time, which makes jar ~8 MB, whereas zip for NodeJs ~1.4 MB
  3. Based on above 2 points, is it safe to conclude that NodeJS based lambda is much better than java based lambda when need to access parameter store?
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Guru
  • 964
  • 9
  • 12
  • Can it be related to the cold start where Java almost always takes longer compared to Node.js? I.e. did you retrieve the numbers from the first invocation of your Lambda function or did you get them after invoking the functions multiple times? – s.hesse Aug 21 '20 at 16:39
  • Thanks, numbers mentioned are for the the first call but not end-to-end execution of lambda. Those are the time taken to read a parameter from SSM parameter store. Without call to parameter store, cold start time noticed is ~200 ms for java – Guru Aug 25 '20 at 15:49
  • @AtulKulkarni did you find the reason why is Java taking way more than Node? – Luis Miguel Nov 12 '20 at 21:44
  • Not yet. Have parked it for now. Are you also facing similar challenge? – Guru Nov 13 '20 at 11:24
  • yeah, I'm facing the same issue. With Java using https://awslabs.github.io/aws-lambda-powertools-java/utilities/parameters/ the Lambda takes from 8-12 seconds to execute. Using NodeJs with a simple code it takes less than a second. – Luis Miguel Nov 13 '20 at 19:22
  • @AtulKulkarni We are also facing the similar cold start issue with our java lambda. Any updates on your side ? – pinaki Apr 28 '22 at 09:38

0 Answers0