From 446c62f98a3e75b2397f9c2e0f65c4b42bbb19f6 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Tue, 6 Aug 2024 11:35:54 -0500 Subject: [PATCH] Instantiate SSMClient in the AWSParameterStoreSecretsVault constructor --- .../core/src/lib/adapters/aws-param-store.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/infra/core/src/lib/adapters/aws-param-store.ts b/infra/core/src/lib/adapters/aws-param-store.ts index 769dd6a8..f25e3f1b 100644 --- a/infra/core/src/lib/adapters/aws-param-store.ts +++ b/infra/core/src/lib/adapters/aws-param-store.ts @@ -12,10 +12,15 @@ import { import type { SecretKey, SecretMap, SecretValue, SecretsVault } from '../types'; export class AWSParameterStoreSecretsVault implements SecretsVault { + client: SSMClient; + + constructor() { + this.client = new SSMClient(); + } + async deleteSecret(key: SecretKey) { - const client = new SSMClient(); try { - await client.send( + await this.client.send( new DeleteParameterCommand({ Name: key, }) @@ -27,10 +32,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault { } async getSecret(key: SecretKey) { - const client = new SSMClient(); - try { - const response = await client.send( + const response = await this.client.send( new GetParameterCommand({ Name: key, WithDecryption: true, @@ -47,9 +50,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault { } async getSecrets(keys: SecretKey[]) { - const client = new SSMClient(); try { - const response = await client.send( + const response = await this.client.send( new GetParametersCommand({ Names: keys, WithDecryption: true, @@ -71,9 +73,8 @@ export class AWSParameterStoreSecretsVault implements SecretsVault { } async setSecret(key: SecretKey, value: SecretValue) { - const client = new SSMClient(); try { - await client.send( + await this.client.send( new PutParameterCommand({ Name: key, Value: value, @@ -96,18 +97,17 @@ export class AWSParameterStoreSecretsVault implements SecretsVault { } async getSecretKeys() { - const client = new SSMClient(); - let keys: string[] = []; let nextToken: string | undefined; do { try { - const response: DescribeParametersCommandOutput = await client.send( - new DescribeParametersCommand({ - NextToken: nextToken, - MaxResults: 50, - }) - ); + const response: DescribeParametersCommandOutput = + await this.client.send( + new DescribeParametersCommand({ + NextToken: nextToken, + MaxResults: 50, + }) + ); if (response.Parameters) { keys.push(...response.Parameters.map(param => param.Name!)); }