Skip to content

Commit 76c1b37

Browse files
sophia-bqSophia Chu
andauthored
docs: using the aws secrets manager plugin (#254)
Co-authored-by: Sophia Chu <[email protected]>
1 parent c2e09e2 commit 76c1b37

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# AWS Secrets Manager Plugin
2+
3+
The AWS Advanced NodeJS Wrapper supports usage of database credentials stored as secrets in the [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) through the AWS Secrets Manager Connection Plugin. When you create a new connection with this plugin enabled, the plugin will retrieve the secret and the connection will be created with the credentials inside that secret.
4+
5+
## Prerequisites
6+
7+
- This plugin requires the following packages to be installed:
8+
- [@aws-sdk/client-secrets-manager](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-secrets-manager/)
9+
10+
## Enabling the AWS Secrets Manager Connection Plugin
11+
12+
To enable the AWS Secrets Manager Connection Plugin, add the plugin code `secretsManager` to the [`plugins`](../UsingTheNodejsWrapper.md#connection-plugin-manager-parameters) connection parameter.
13+
14+
This plugin requires a valid set of AWS credentials to retrieve the database credentials from AWS Secrets Manager. The AWS credentials must be located in [one of these locations](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-credential-providers/#fromNodeProviderChain) supported by the AWS SDK's default credentials provider.
15+
16+
## AWS Secrets Manager Connection Plugin Parameters
17+
18+
The following properties are required for the AWS Secrets Manager Connection Plugin to retrieve database credentials from the AWS Secrets Manager.
19+
20+
> [!NOTE]
21+
> To use this plugin, you will need to set the following AWS Secrets Manager specific parameters.
22+
23+
| Parameter | Value | Required | Description | Example | Default Value |
24+
| ---------------- | :----: | :------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------- | ------------- |
25+
| `secretId` | String | Yes | Set this value to be the secret name or the secret ARN. | `secretId` | `null` |
26+
| `secretRegion` | String | No | Set this value to be the region your secret is in. | `us-east-2` | `us-east-1` |
27+
| `secretEndpoint` | String | No | Set this value to be the endpoint override to retrieve your secret from. This parameter value should be in the form of a URL, with a valid protocol (ex. `https://`) and domain (ex. `localhost`). A port number is not required. | `https://localhost:1234` | `null` |
28+
29+
> [!NOTE]
30+
> A Secret ARN has the following format: `arn:aws:secretsmanager:<Region>:<AccountId>:secret:SecretName-6RandomCharacters`
31+
32+
## Secret Data
33+
34+
The plugin assumes that the secret contains the following properties `username` and `password`.
35+
36+
### Example
37+
38+
Examples of making a connection using credentials fetched from the AWS Secrets Manager can be found at:
39+
[PostgreSQL example](../../../examples/aws_driver_example/aws_secrets_manager_postgresql_example.ts) and [MySQL example](../../../examples/aws_driver_example/aws_secrets_manager_mysql_example.ts)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { AwsMySQLClient } from "../../mysql/lib";
18+
19+
const mysqlHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com";
20+
const port = 3306;
21+
const secretId = "id";
22+
23+
const client = new AwsMySQLClient({
24+
// Enable the AWS Secrets Manager Connection Plugin and configure connection parameters.
25+
host: mysqlHost,
26+
port: port,
27+
secretId: secretId,
28+
plugins: "secretsManager"
29+
});
30+
31+
// Attempt connection.
32+
try {
33+
await client.connect();
34+
const result = await client.query({ sql: "SELECT 1" });
35+
console.log(result);
36+
} finally {
37+
await client.end();
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { AwsPGClient } from "../../pg/lib";
18+
19+
const postgresHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com";
20+
const database = "employees";
21+
const port = 5432;
22+
const secretId = "id";
23+
24+
const client = new AwsPGClient({
25+
// Enable the AWS Secrets Manager Connection Plugin and configure connection parameters.
26+
host: postgresHost,
27+
database: database,
28+
port: port,
29+
secretId: secretId,
30+
plugins: "secretsManager"
31+
});
32+
33+
// Attempt connection.
34+
try {
35+
await client.connect();
36+
const result = await client.query("select 1");
37+
console.log(result);
38+
} finally {
39+
await client.end();
40+
}

0 commit comments

Comments
 (0)