Description
Summary
Hello,
I am currently doing some performance tuning in our lambda functions and i notice that getting SSM parameters introduce some latency in the first execution. I've executed tests using both the getParameter utility and also SSMProvider. These were my findings:
ssm client instantiation: ~50ms
ssm provider instantiation: ~50ms
getParameter: 380ms (discounting 300ms from SDK, ~80ms)
SSM SDK get parameter: 300ms
In my tests I've used lambda functions configured with provisioned concurrency, so I tried to bring some of the latency to the INIT phase. I understand the best way to do it would be to:
- Instantiante the SSM client in the static scope, maybe using a capture to trace this call
- Passing the client to SSMProvider
- Using SSMProvider instead of getParameter utility, which would add the latency of instantiating a SSM client inside the handler code.
However, I haven't noticed any gain of doing that. By inspecting the code bellow, I've noticed that SSM client is instantiated even when it's not used, i.e., when one passes the client as parameter. I believe this section could be optimized so that SSM client is only instantiated if none is available:
/**
* It initializes the SSMProvider class.
*
* @param {SSMProviderOptions} config - The configuration object.
*/
public constructor(config?: SSMProviderOptions) {
super();
this.client = new SSMClient(config?.clientConfig || {});
if (config?.awsSdkV3Client) {
if (isSdkClient(config.awsSdkV3Client)) {
this.client = config.awsSdkV3Client;
} else {
console.warn(
'awsSdkV3Client is not an AWS SDK v3 client, using default client'
);
}
}
addUserAgentMiddleware(this.client, 'parameters');
}
Why is this needed?
Improve performance of first execution when SSMProvider has a SSM client.
Which area does this relate to?
Parameters
Solution
Instantiate SSM client only when none is available
Acknowledgment
- This request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status