API reference / @backpack/aws-secrets-manager / SecretsManagerService
Class: SecretsManagerService
Retrieves secrets from AWS Secret Manager.
Example
ts
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
import { SecretsManagerService } from "@backpack/aws-secrets-manager";
const client = new SecretsManagerClient();
const service = new SecretsManagerService(client);
const mySecret = service.getJsonSecret("/my/secret-id");
// ^ inferred as `unknown`, throws error if not found
type MySecret = { foo: string; bar: string; };
const typedSecret = service.getJsonSecret<MySecret>("/my/secret-id");
// ^ inferred as `MySecret`, throws error if not found
const optionalSecret = service.getJsonSecret<MySecret>("/my/secret-id", { required: false });
// ^ inferred as `MySecret | undefined`
Extended by
Constructors
Constructor
ts
new SecretsManagerService(secretsManagerClient): SecretsManagerService;
Parameters
Parameter | Type | Description |
---|---|---|
secretsManagerClient | SecretsManagerClient | The Secrets Manager client from AWS SDK. |
Returns
SecretsManagerService
Properties
client
ts
protected readonly client: SecretsManagerClient;
Methods
getJsonSecret()
Call Signature
ts
getJsonSecret<T>(secretId, options?): Promise<T>;
Retrieves and parses a secret value stored as JSON.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
secretId | string | The id of the secret to retrieve. |
options? | { required : true ; } | Additional options. |
options.required? | true | - |
Returns
Promise
<T
>
Throws
Error
if the secret was not found and options.required
is true.
Call Signature
ts
getJsonSecret<T>(secretId, options?): Promise<undefined | T>;
Retrieves and parses a secret value stored as JSON.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
secretId | string | The id of the secret to retrieve. |
options? | { required : boolean ; } | Additional options. |
options.required? | boolean | - |
Returns
Promise
<undefined
| T
>
Throws
Error
if the secret was not found and options.required
is true.
getRequiredSecretValue()
ts
getRequiredSecretValue<T>(secretId): Promise<T>;
Retrieves and parses a secret value stored as JSON.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
secretId | string | The id of the secret to retrieve. |
Returns
Promise
<T
>
Deprecated
use getJsonSecret()
instead.
getSecretValue()
ts
getSecretValue<T>(secretId): Promise<undefined | T>;
Retrieves and parses a secret value stored as JSON.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
secretId | string | The id of the secret to retrieve. |
Returns
Promise
<undefined
| T
>
Deprecated
use getJsonSecret(secretId, { required: false })
instead.