Skip to content

Maintenance: initialize AWS SDK client only when needed to improve performance in Parameters #1740

Closed
@marcioemiranda

Description

@marcioemiranda

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:

  1. Instantiante the SSM client in the static scope, maybe using a capture to trace this call
  2. Passing the client to SSMProvider
  3. 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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedgood-first-issueSomething that is suitable for those who want to start contributingparametersThis item relates to the Parameters Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions