我正在尝试从lambda访问SSM参数存储。从基于Java AWS开发工具包的lambda获取参数与基于NodeJS AWS开发工具包的lambda获取参数时,我注意到性能上的主要差异。
基于Java的lambda来获取参数的示例代码:
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();
}
}
基于NodeJS的lambda来获取参数的示例代码:
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;