Skip to content

Commit 548ff4f

Browse files
author
Victor Tsang
committed
use env variable for all examples
1 parent 3b681db commit 548ff4f

8 files changed

Lines changed: 86 additions & 22 deletions

javascript/cluster_management/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@ working example for each operation.
2424
- [Node 18.0.0](https://nodejs.org) or later.
2525
- Valid AWS credentials can be discovered by the [default provider chain](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials-chain.html).
2626

27+
### Configure the environment
28+
29+
Set environment variables with your cluster details as required.
30+
31+
#### Single-region clusters
32+
33+
```bash
34+
# Only relevant for delete/get/update examples.
35+
# e.g. "foo0bar1baz2quux3quuux4"
36+
export CLUSTER_ID="<your id>"
37+
38+
# Relevant for all examples.
39+
# e.g. "us-east-1"
40+
export CLUSTER_REGION="<your region>"
41+
```
42+
43+
#### Multi-region clusters
44+
45+
```bash
46+
# Only relevant for delete/get/update examples.
47+
# e.g. "foo0bar1baz2quux3quuux4" and "foo5bar6baz7quux8quuux9"
48+
export CLUSTER_1_ID="<your id 1>"
49+
export CLUSTER_2_ID="<your id 2>"
50+
51+
# Relevant for all examples.
52+
# e.g. "us-east-1" and "us-east-2"
53+
export CLUSTER_1_REGION="<your region 1>"
54+
export CLUSTER_2_REGION="<your region 2>"
55+
56+
# Only relevant for create examples.
57+
# e.g. "us-west-2"
58+
export WITNESS_REGION="<your region 3>"
59+
```
60+
2761
### Execute tests to create and delete clusters
2862

2963
```
@@ -32,6 +66,16 @@ npm install
3266
npm test
3367
```
3468

69+
### Executing single operations
70+
71+
Files in the [/src](src) directory have a main() method that lets you exercise single operations.
72+
73+
```
74+
# Check each operation for its expected environment variables
75+
REGION_1="us-east-1" CLUSTER_ID="<your cluster id>" \
76+
node ./src/get_cluster.js
77+
```
78+
3579
---
3680

3781
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

javascript/cluster_management/src/create_multi_region_clusters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export async function createMultiRegionCluster(region1, region2, witnessRegion)
8888
}
8989

9090
async function main() {
91-
const region1 = "us-east-1";
92-
const region2 = "us-east-2";
93-
const witnessRegion = "us-west-2";
91+
const region1 = process.env.CLUSTER_1_REGION || "us-east-1";
92+
const region2 = process.env.CLUSTER_2_REGION || "us-east-2";
93+
const witnessRegion = process.env.WITNESS_REGION || "us-west-2";
9494

9595
await createMultiRegionCluster(region1, region2, witnessRegion);
9696
}

javascript/cluster_management/src/create_single_region_cluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function createCluster(region) {
3333
}
3434

3535
async function main() {
36-
const region = "us-east-1";
36+
const region = process.env.CLUSTER_REGION || "us-east-1";
3737
const cluster = await createCluster(region);
3838
console.log(`Created ${cluster}`);
3939
}

javascript/cluster_management/src/delete_multi_region_clusters.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { DSQLClient, DeleteClusterCommand, waitUntilClusterNotExists } from "@aws-sdk/client-dsql";
22

3-
export async function deleteMultiRegionClusters(region1, cluster1_id, region2, cluster2_id) {
3+
export async function deleteMultiRegionClusters(region1, cluster1Id, region2, cluster2Id) {
44

55
const client1 = new DSQLClient({ region: region1 });
66
const client2 = new DSQLClient({ region: region2 });
77

88
try {
99
const deleteClusterCommand1 = new DeleteClusterCommand({
10-
identifier: cluster1_id,
10+
identifier: cluster1Id,
1111
});
1212
const response1 = await client1.send(deleteClusterCommand1);
1313

1414
const deleteClusterCommand2 = new DeleteClusterCommand({
15-
identifier: cluster2_id,
15+
identifier: cluster2Id,
1616
});
1717
const response2 = await client2.send(deleteClusterCommand2);
1818

@@ -51,13 +51,18 @@ export async function deleteMultiRegionClusters(region1, cluster1_id, region2, c
5151
}
5252

5353
async function main() {
54-
const region1 = "us-east-1";
55-
const cluster1_id = "<CLUSTER_ID_1>";
56-
const region2 = "us-east-2";
57-
const cluster2_id = "<CLUSTER_ID_2>";
54+
const region1 = process.env.CLUSTER_1_REGION || "us-east-1";
55+
const cluster1Id = process.env.CLUSTER_1_ID;
56+
const region2 = process.env.CLUSTER_2_REGION || "us-east-2";
57+
const cluster2Id = process.env.CLUSTER_2_ID;
5858

59-
const response = await deleteMultiRegionClusters(region1, cluster1_id, region2, cluster2_id);
60-
console.log(`Deleted ${cluster1_id} in ${region1} and ${cluster2_id} in ${region2}`);
59+
if (!cluster1_id || !cluster2_id) {
60+
console.error("Error: CLUSTER_1_ID and CLUSTER_2_ID environment variables must be set");
61+
process.exit(1);
62+
}
63+
64+
await deleteMultiRegionClusters(region1, cluster1Id, region2, cluster2Id);
65+
console.log(`Deleted ${cluster1Id} in ${region1} and ${cluster2Id} in ${region2}`);
6166
}
6267

6368
if (process.env.NODE_ENV !== 'test') {

javascript/cluster_management/src/delete_single_region_cluster.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ export async function deleteCluster(region, clusterId) {
3434
}
3535

3636
async function main() {
37-
const region = "us-east-1";
38-
const clusterId = "<CLUSTER_ID>";
37+
const region = process.env.CLUSTER_REGION || "us-east-1";
38+
const clusterId = process.env.CLUSTER_ID;
39+
40+
if (!clusterId) {
41+
console.error("Error: CLUSTER_ID environment variables must be set");
42+
process.exit(1);
43+
}
3944

4045
await deleteCluster(region, clusterId);
4146
}

javascript/cluster_management/src/get_cluster.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ export async function getCluster(region, clusterId) {
1919
}
2020

2121
async function main() {
22-
const region = "us-east-1";
23-
const clusterId = "<CLUSTER_ID>";
22+
const region = process.env.CLUSTER_REGION || "us-east-1";
23+
const clusterId = process.env.CLUSTER_ID;
24+
25+
if (!clusterId) {
26+
console.error("Error: CLUSTER_ID environment variables must be set");
27+
process.exit(1);
28+
}
2429

2530
const response = await getCluster(region, clusterId);
2631
console.log("Cluster: ", response);

javascript/cluster_management/src/update_cluster.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ export async function updateCluster(region, clusterId, deletionProtectionEnabled
1818
}
1919

2020
async function main() {
21-
const region = "us-east-1";
22-
const clusterId = "<CLUSTER_ID>";
21+
const region = process.env.CLUSTER_REGION || "us-east-1";
22+
const clusterId = process.env.CLUSTER_ID;
23+
24+
if (!clusterId) {
25+
console.error("Error: CLUSTER_ID environment variables must be set");
26+
process.exit(1);
27+
}
2328

2429
const response = await updateCluster(region, clusterId, false);
2530
console.log(`Updated ${response.arn}`);

javascript/cluster_management/test/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ test('Single region cluster test', async function () {
2929

3030
test('Multi region clusters test', async function () {
3131

32-
const region1 = 'us-east-1';
33-
const region2 = 'us-east-2';
34-
const witnessRegion = 'us-west-2';
32+
const region1 = process.env.CLUSTER_1_REGION || "us-east-1";
33+
const region2 = process.env.CLUSTER_2_REGION || "us-east-2";
34+
const witnessRegion = process.env.WITNESS_REGION || "us-west-2";
3535

3636
console.log("Starting multi region clusters lifecycle run");
3737
const { cluster1Id, cluster2Id } = await createMultiRegionCluster(region1, region2, witnessRegion);

0 commit comments

Comments
 (0)