From 778382bc66a4c62fc04ff09f7125f84f9b9d60dd Mon Sep 17 00:00:00 2001 From: Mo Kamioner Date: Wed, 5 Nov 2025 15:26:29 +0200 Subject: [PATCH] Remove references to deprecated javascript V2 SDK --- .../basic-template/basic-backend/package.json | 1 - .../enhanced-backend/package.json | 1 - .../NERDS/recipe-example/backend/package.json | 1 - examples/SDK/node.js/Operations.md | 63 ------- .../add-global-table-region.js | 6 +- .../WorkingWithTables/create-global-table.js | 7 +- .../delete-global-table-region.js | 7 +- ...-global-table-and-global-table-settings.js | 10 +- .../WorkingWithTables/describe_table.js | 13 +- .../WorkingWithTables/disable_auto_scaling.js | 78 +++++---- .../enable_auto_scaling_v2.js | 156 +++++++++--------- ...-global-table-and-global-table-settings.js | 10 +- .../update_auto_scaling_v2.js | 49 +++--- .../update-item-conditional.js | 41 ----- .../scan-parallel-segments.js | 35 ++-- .../create-workbench-import.js | 18 +- 16 files changed, 190 insertions(+), 306 deletions(-) delete mode 100644 examples/SDK/node.js/Operations.md diff --git a/examples/NERDS/basic-template/basic-backend/package.json b/examples/NERDS/basic-template/basic-backend/package.json index 0126fc8..34f3f6e 100644 --- a/examples/NERDS/basic-template/basic-backend/package.json +++ b/examples/NERDS/basic-template/basic-backend/package.json @@ -7,7 +7,6 @@ "@aws-sdk/client-dynamodb": "^3.620.0", "@aws-sdk/lib-dynamodb": "^3.620.0", "@aws-sdk/util-dynamodb": "^3.620.0", - "aws-sdk": "^2.1664.0", "body-parser": "^1.20.2", "cors": "^2.8.5", "express": "^4.19.2", diff --git a/examples/NERDS/enhanced-template/enhanced-backend/package.json b/examples/NERDS/enhanced-template/enhanced-backend/package.json index 9f5db02..9c320e6 100644 --- a/examples/NERDS/enhanced-template/enhanced-backend/package.json +++ b/examples/NERDS/enhanced-template/enhanced-backend/package.json @@ -7,7 +7,6 @@ "@aws-sdk/client-dynamodb": "^3.620.0", "@aws-sdk/lib-dynamodb": "^3.620.0", "@aws-sdk/util-dynamodb": "^3.620.0", - "aws-sdk": "^2.1664.0", "body-parser": "^1.20.2", "cors": "^2.8.5", "express": "^4.19.2", diff --git a/examples/NERDS/recipe-example/backend/package.json b/examples/NERDS/recipe-example/backend/package.json index 92938d9..c895653 100644 --- a/examples/NERDS/recipe-example/backend/package.json +++ b/examples/NERDS/recipe-example/backend/package.json @@ -10,7 +10,6 @@ "nanoid": "^5.0.7" }, "devDependencies": { - "aws-sdk-client-mock": "^2.0.0", "esbuild": "^0.14.54", "jest": "^29.2.1" }, diff --git a/examples/SDK/node.js/Operations.md b/examples/SDK/node.js/Operations.md deleted file mode 100644 index ff02c63..0000000 --- a/examples/SDK/node.js/Operations.md +++ /dev/null @@ -1,63 +0,0 @@ -# Supported Operations - Table needs to be updated - -| Operation | Node.js SDK v3 | Node.js SDK v2 | -| --------------------------------------------------- | :------------: | :------------: | -| BatchGet | ✅ | ❌ | -| BatchWrite | ✅ | ❌ | -| DeleteItem | ✅ | ❌ | -| DeleteItemConditional | ✅ | ❌ | -| GetItem | ✅ | ❌ | -| PutItem | ✅ | ❌ | -| PutItemConditional | ✅ | ❌ | -| TransactGet | ✅ | ❌ | -| TransactWrite | ✅ | ❌ | -| UpdateItem | ✅ | ❌ | -| UpdateItemConditional | ✅ | ❌ | -| PartiQL SimpleSelectStatement | ✅ | ❌ | -| PartiQL ExecuteStatement | ✅ | ❌ | -| PartiQL ExecuteTransaction | ✅ | ❌ | -| PartiQL BatchExecuteStatement | ✅ | ❌ | -| Create Index | ✅ | ❌ | -| Update Index Provisioned Capacity | ✅ | ❌ | -| Delete Index | ✅ | ❌ | -| Query Index | ❌ | ❌ | -| Consistent read | ✅ | ❌ | -| Count | ✅ | ❌ | -| Filter expression | ✅ | ❌ | -| Key condition and begins_with | ✅ | ❌ | -| Key condition, begins_with, sort order | ✅ | ❌ | -| Key condition and between dates | ✅ | ❌ | -| Key condition and between numbers | ✅ | ❌ | -| Key condition and equals | ✅ | ❌ | -| Key condition and greater or equals | ✅ | ❌ | -| Key condition and greater than | ✅ | ❌ | -| Key condition and less or equals | ✅ | ❌ | -| Key condition and less | ✅ | ❌ | -| Query with pagination | ✅ | ❌ | -| Query with pagination - all data | ✅ | ❌ | -| Query with backwards pagination | ✅ | ❌ | -| Projection expression | ✅ | ❌ | -| Scan with Pagination | ✅ | ❌ | -| Scan Parallel Segments | ✅ | ❌ | -| Read from stream | ✅ | ❌ | -| Add Global Table Region | ✅ | ❌ | -| Add Provisioned Capacity | ✅ | ❌ | -| CreateTable On-Demand | ✅ | ❌ | -| CreateTable Provisioned | ✅ | ❌ | -| Delete Global Table Region | ✅ | ❌ | -| DeleteTable | ✅ | ❌ | -| DescribeGlobalTable and DescribeGlobalTableSettings | ✅ | ❌ | -| DescribeLimits | ✅ | ❌ | -| DescribeTable | ✅ | ❌ | -| Disable Autoscaling | ✅ | ❌ | -| Enable Autoscaling | ❌ | ✅ | -| Update Autoscaling | ❌ | ✅ | -| Disable Streams | ✅ | ❌ | -| Enable Streams | ✅ | ❌ | -| ListTables | ✅ | ❌ | -| UpdateGlobalTable and UpdateGlobalTableSettings | ✅ | ❌ | -| UpdateTable On-Demand | ✅ | ❌ | -| UpdateTable Provisioned | ✅ | ❌ | -| Create an on-demand backup | ✅ | ❌ | -| Delete backup | ✅ | ❌ | -| Describe backup | ✅ | ❌ | diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/add-global-table-region.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/add-global-table-region.js index affd035..5e329d1 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/add-global-table-region.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/add-global-table-region.js @@ -1,10 +1,6 @@ -//const AWS = require("aws-sdk"); - -//const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); -const { DynamoDBClient, UpdateTableCommand, UpdateGlobalTableCommand } = require('@aws-sdk/client-dynamodb'); +const { DynamoDBClient, UpdateTableCommand } = require('@aws-sdk/client-dynamodb'); const REGION = "us-west-2"; -//const TABLENAME = "RetailDatabase"; async function addGlobalTableRegion() { const params = { diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/create-global-table.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/create-global-table.js index 92c9895..97200a8 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/create-global-table.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/create-global-table.js @@ -1,6 +1,6 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient, CreateGlobalTableCommand } = require("@aws-sdk/client-dynamodb"); -const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); +const dynamodb = new DynamoDBClient({ region: "us-west-2" }); const tableName = "Music"; @@ -15,7 +15,8 @@ async function createGlobalTable() { ], }; - const response = await dynamodb.createGlobalTable(params).promise(); + const command = new CreateGlobalTableCommand(params); + const response = await dynamodb.send(command); return response; } diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/delete-global-table-region.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/delete-global-table-region.js index 8325e06..85c283d 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/delete-global-table-region.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/delete-global-table-region.js @@ -1,6 +1,6 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient, UpdateTableCommand } = require("@aws-sdk/client-dynamodb"); -const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); +const dynamodb = new DynamoDBClient({ region: "us-west-2" }); const tableName = "Music"; @@ -16,7 +16,8 @@ async function deleteGlobalTableRegion() { ], }; - const response = await dynamodb.updateTable(params).promise(); + const command = new UpdateTableCommand(params); + const response = await dynamodb.send(command); return response; } diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe-global-table-and-global-table-settings.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe-global-table-and-global-table-settings.js index a73b7f9..462091d 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe-global-table-and-global-table-settings.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe-global-table-and-global-table-settings.js @@ -1,6 +1,6 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient, DescribeGlobalTableCommand, DescribeGlobalTableSettingsCommand } = require("@aws-sdk/client-dynamodb"); -const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); +const dynamodb = new DynamoDBClient({ region: "us-west-2" }); const tableName = "Music"; @@ -10,7 +10,8 @@ async function describeGlobalTable() { GlobalTableName: tableName, }; - const response = await dynamodb.describeGlobalTable(params).promise(); + const command = new DescribeGlobalTableCommand(params); + const response = await dynamodb.send(command); return response; } @@ -20,7 +21,8 @@ async function describeGlobalTableSettings() { GlobalTableName: tableName, }; - const response = await dynamodb.describeGlobalTableSettings(params).promise(); + const command = new DescribeGlobalTableSettingsCommand(params); + const response = await dynamodb.send(command); return response; } diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe_table.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe_table.js index 522af9f..9eeb5fa 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe_table.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/describe_table.js @@ -1,15 +1,14 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient, DescribeTableCommand } = require("@aws-sdk/client-dynamodb"); -const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); +const dynamodb = new DynamoDBClient({ region: "us-west-2" }); const describeTable = async () => { - const response = await dynamodb - .describeTable({ TableName: "Music" }) // Substitute your table name for "Music" - .promise(); + const command = new DescribeTableCommand({ TableName: "Music" }); // Substitute your table name for "Music" + const response = await dynamodb.send(command); //console.log(JSON.stringify(response, null, 2)); - let test = JSON.stringify(response.Table.StreamSpecification.StreamEnabled, null, 2) - console.log(test) + const streamEnabled = JSON.stringify(response.Table.StreamSpecification.StreamEnabled, null, 2) + console.log(streamEnabled); }; describeTable().catch((error) => console.error(JSON.stringify(error, null, 2))); diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/disable_auto_scaling.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/disable_auto_scaling.js index 28f00f5..e31fb23 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/disable_auto_scaling.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/disable_auto_scaling.js @@ -1,50 +1,48 @@ -const AWS = require("aws-sdk"); +const { + ApplicationAutoScalingClient, + DeleteScalingPolicyCommand, + DeregisterScalableTargetCommand +} = require("@aws-sdk/client-application-auto-scaling"); -const applicationAutoscaling = new AWS.ApplicationAutoScaling({ - apiVersion: "2016-02-06", +const applicationAutoscaling = new ApplicationAutoScalingClient({ region: "us-west-2", - logger: console, }); const tableName = "Music"; // Add the name of the DynamoDB table you want to add auto-scaling to between the double quotes. const disableAutoScaling = async () => { - // Attach the Read scaling policy to the table. - let response = await applicationAutoscaling - .deleteScalingPolicy({ - PolicyName: `${tableName}ScalingPolicy`, - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:ReadCapacityUnits", - }) - .promise(); - - response = await applicationAutoscaling - .deleteScalingPolicy({ - PolicyName: `${tableName}ScalingPolicy`, - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:WriteCapacityUnits", - }) - .promise(); - - // Register the RCU targets for the table - response = await applicationAutoscaling - .deregisterScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:ReadCapacityUnits", - }) - .promise(); - - // Register the RCU targets for the table - response = await applicationAutoscaling - .deregisterScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:WriteCapacityUnits", - }) - .promise(); + // Delete the Read scaling policy from the table. + let command = new DeleteScalingPolicyCommand({ + PolicyName: `${tableName}ScalingPolicy`, + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:ReadCapacityUnits", + }); + let response = await applicationAutoscaling.send(command); + + command = new DeleteScalingPolicyCommand({ + PolicyName: `${tableName}ScalingPolicy`, + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:WriteCapacityUnits", + }); + response = await applicationAutoscaling.send(command); + + // Deregister the RCU targets for the table + command = new DeregisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:ReadCapacityUnits", + }); + response = await applicationAutoscaling.send(command); + + // Deregister the WCU targets for the table + command = new DeregisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:WriteCapacityUnits", + }); + response = await applicationAutoscaling.send(command); console.log("Autoscaling has been disabled"); }; diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/enable_auto_scaling_v2.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/enable_auto_scaling_v2.js index f4f4379..0a6c0b5 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/enable_auto_scaling_v2.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/enable_auto_scaling_v2.js @@ -1,10 +1,13 @@ -const AWS = require("aws-sdk"); +const { IAMClient, CreateRoleCommand, CreatePolicyCommand, AttachRolePolicyCommand } = require("@aws-sdk/client-iam"); +const { + ApplicationAutoScalingClient, + RegisterScalableTargetCommand, + PutScalingPolicyCommand +} = require("@aws-sdk/client-application-auto-scaling"); -const iam = new AWS.IAM({ apiVersion: "2010-05-08", region: "us-west-2", logger: console }); -const applicationAutoscaling = new AWS.ApplicationAutoScaling({ - apiVersion: "2016-02-06", +const iam = new IAMClient({ region: "us-west-2" }); +const applicationAutoscaling = new ApplicationAutoScalingClient({ region: "us-west-2", - logger: console, }); const tableName = "Music"; @@ -50,96 +53,89 @@ const policyDocument = { const enableAutoScaling = async () => { // Create the role necessary for auto-scaling + const createRoleCommand = new CreateRoleCommand({ + AssumeRolePolicyDocument: JSON.stringify(assumeRolePolicyDocument), + RoleName: roleName, + Description: `Table scaling role for ${tableName}`, + MaxSessionDuration: 3600, + Path: "/", + }); const { Role: { Arn: roleArn }, - } = await iam - .createRole({ - AssumeRolePolicyDocument: JSON.stringify(assumeRolePolicyDocument), - RoleName: roleName, - Description: `Table scaling role for ${tableName}`, - MaxSessionDuration: 3600, - Path: "/", - }) - .promise(); + } = await iam.send(createRoleCommand); // Create the policy needed by the role + const createPolicyCommand = new CreatePolicyCommand({ + PolicyDocument: JSON.stringify(policyDocument), + PolicyName: policyName, + Path: "/", + }); const { Policy: { Arn: policyArn }, - } = await iam - .createPolicy({ - PolicyDocument: JSON.stringify(policyDocument), - PolicyName: policyName, - Path: "/", - }) - .promise(); + } = await iam.send(createPolicyCommand); // Attach the policy to the role so it can be used. - let response = await iam - .attachRolePolicy({ - RoleName: roleName, - PolicyArn: policyArn, - }) - .promise(); + const attachPolicyCommand = new AttachRolePolicyCommand({ + RoleName: roleName, + PolicyArn: policyArn, + }); + let response = await iam.send(attachPolicyCommand); // Register the RCU targets for the table - response = await applicationAutoscaling - .registerScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:ReadCapacityUnits", - MinCapacity: minCapacity, - MaxCapacity: maxCapacity, - RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", - }) - .promise(); + let registerCommand = new RegisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:ReadCapacityUnits", + MinCapacity: minCapacity, + MaxCapacity: maxCapacity, + RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", + }); + response = await applicationAutoscaling.send(registerCommand); - // Register the RCU targets for the table - response = await applicationAutoscaling - .registerScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:WriteCapacityUnits", - MinCapacity: minCapacity, - MaxCapacity: maxCapacity, - RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", - }) - .promise(); + // Register the WCU targets for the table + registerCommand = new RegisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:WriteCapacityUnits", + MinCapacity: minCapacity, + MaxCapacity: maxCapacity, + RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", + }); + response = await applicationAutoscaling.send(registerCommand); // Attach the Read scaling policy to the table. - response = await applicationAutoscaling - .putScalingPolicy({ - PolicyName: `${tableName}ScalingPolicy`, - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:ReadCapacityUnits", - PolicyType: "TargetTrackingScaling", - TargetTrackingScalingPolicyConfiguration: { - TargetValue: readTarget, - PredefinedMetricSpecification: { PredefinedMetricType: "DynamoDBReadCapacityUtilization" }, - ScaleOutCooldown: cooldownDurationSec, - ScaleInCooldown: cooldownDurationSec, - DisableScaleIn: true, - }, - }) - .promise(); + let policyCommand = new PutScalingPolicyCommand({ + PolicyName: `${tableName}ScalingPolicy`, + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:ReadCapacityUnits", + PolicyType: "TargetTrackingScaling", + TargetTrackingScalingPolicyConfiguration: { + TargetValue: readTarget, + PredefinedMetricSpecification: { PredefinedMetricType: "DynamoDBReadCapacityUtilization" }, + ScaleOutCooldown: cooldownDurationSec, + ScaleInCooldown: cooldownDurationSec, + DisableScaleIn: true, + }, + }); + response = await applicationAutoscaling.send(policyCommand); // Attach the Write scaling policy to the table. - response = await applicationAutoscaling - .putScalingPolicy({ - PolicyName: `${tableName}ScalingPolicy`, - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:WriteCapacityUnits", - PolicyType: "TargetTrackingScaling", - TargetTrackingScalingPolicyConfiguration: { - TargetValue: writeTarget, - PredefinedMetricSpecification: { PredefinedMetricType: "DynamoDBWriteCapacityUtilization" }, - ScaleOutCooldown: cooldownDurationSec, - ScaleInCooldown: cooldownDurationSec, - DisableScaleIn: true, - }, - }) - .promise(); + policyCommand = new PutScalingPolicyCommand({ + PolicyName: `${tableName}ScalingPolicy`, + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:WriteCapacityUnits", + PolicyType: "TargetTrackingScaling", + TargetTrackingScalingPolicyConfiguration: { + TargetValue: writeTarget, + PredefinedMetricSpecification: { PredefinedMetricType: "DynamoDBWriteCapacityUtilization" }, + ScaleOutCooldown: cooldownDurationSec, + ScaleInCooldown: cooldownDurationSec, + DisableScaleIn: true, + }, + }); + response = await applicationAutoscaling.send(policyCommand); console.log("Autoscaling has been enabled"); }; diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update-global-table-and-global-table-settings.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update-global-table-and-global-table-settings.js index 4131471..1da1a20 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update-global-table-and-global-table-settings.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update-global-table-and-global-table-settings.js @@ -1,6 +1,6 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient, UpdateGlobalTableCommand, UpdateGlobalTableSettingsCommand } = require("@aws-sdk/client-dynamodb"); -const dynamodb = new AWS.DynamoDB({ region: "us-west-2" }); +const dynamodb = new DynamoDBClient({ region: "us-west-2" }); const tableName = "Music"; @@ -17,7 +17,8 @@ async function updateGlobalTable() { ], }; - const response = await dynamodb.updateGlobalTable(params).promise(); + const command = new UpdateGlobalTableCommand(params); + const response = await dynamodb.send(command); return response; } @@ -27,7 +28,8 @@ async function updateGlobalTableSettings() { GlobalTableProvisionedWriteCapacityUnits: "10", }; - const response = await dynamodb.updateGlobalTableSettings(params).promise(); + const command = new UpdateGlobalTableSettingsCommand(params); + const response = await dynamodb.send(command); return response; } diff --git a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update_auto_scaling_v2.js b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update_auto_scaling_v2.js index 8f97ad6..e20c01b 100644 --- a/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update_auto_scaling_v2.js +++ b/examples/SDK/node.js/sdk_v3/control_plane/WorkingWithTables/update_auto_scaling_v2.js @@ -1,12 +1,7 @@ -const { applicationAutoscalingClient } = require("@aws-sdk/client-application-auto-scaling"); -const { IAMClient, IAM } = require("@aws-sdk/client-iam"); +const { ApplicationAutoScalingClient, RegisterScalableTargetCommand } = require("@aws-sdk/client-application-auto-scaling"); -const AWS = require("aws-sdk"); - -const applicationAutoscaling = new AWS.ApplicationAutoScaling({ - apiVersion: "2016-02-06", +const applicationAutoscaling = new ApplicationAutoScalingClient({ region: "us-west-2", - logger: console, }); const minCapacity = 1; // The minimum capacity for the auto-scaling policy @@ -18,28 +13,26 @@ const tableName = "Music"; const updateAutoScaling = async () => { // Register the RCU targets for the table - response = await applicationAutoscaling - .registerScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:ReadCapacityUnits", - MinCapacity: minCapacity, - MaxCapacity: maxCapacity, - RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", - }) - .promise(); + let command = new RegisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:ReadCapacityUnits", + MinCapacity: minCapacity, + MaxCapacity: maxCapacity, + RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", + }); + let response = await applicationAutoscaling.send(command); - // Register the RCU targets for the table - response = await applicationAutoscaling - .registerScalableTarget({ - ServiceNamespace: "dynamodb", - ResourceId: `table/${tableName}`, - ScalableDimension: "dynamodb:table:WriteCapacityUnits", - MinCapacity: minCapacity, - MaxCapacity: maxCapacity, - RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", - }) - .promise(); + // Register the WCU targets for the table + command = new RegisterScalableTargetCommand({ + ServiceNamespace: "dynamodb", + ResourceId: `table/${tableName}`, + ScalableDimension: "dynamodb:table:WriteCapacityUnits", + MinCapacity: minCapacity, + MaxCapacity: maxCapacity, + RoleARN: "arn:aws:iam::544500146257:role/MusicTableScalingRole", + }); + response = await applicationAutoscaling.send(command); console.log("Autoscaling has been updated"); }; diff --git a/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithItems/update-item-conditional.js b/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithItems/update-item-conditional.js index 109aa3a..d26aa96 100644 --- a/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithItems/update-item-conditional.js +++ b/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithItems/update-item-conditional.js @@ -1,44 +1,3 @@ -/*const AWS = require("aws-sdk"); - -AWS.config.update({ region: "us-west-2" }); - -const documentClient = new AWS.DynamoDB.DocumentClient(); - -// Define the name of a user account to update. Note that in this example, we have to alias "name" using ExpressionAttributeNames as name is a reserved word in DynamoDB. -// Notice also the conditional expression where it will only update if the age is greater than or equal to 21 -async function updateItem() { - const params = { - TableName: "RetailDatabase", - Key: { - pk: "jim.bob@somewhere.com", - sk: "metadata", - }, - ExpressionAttributeNames: { - "#n": "name", - }, - UpdateExpression: "set #n = :nm", - ConditionExpression: "age >= :a", - ExpressionAttributeValues: { - ":nm": "Big Jim Bob", - ":a": 21, - }, - ReturnValues: "ALL_NEW", - }; - - const response = await documentClient.update(params).promise(); - return response; -} - -updateItem() - .then((data) => - console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2)) - ) - .catch((error) => console.error(JSON.stringify(error, null, 2))); */ - - - - - /* This is an example of an UpdateCommand with a Conditional Expression using the higher level DocumentClient for Amazon DynamoDB. It updates one attribute on the item, but it could easily do more if needed. */ diff --git a/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithScans/scan-parallel-segments.js b/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithScans/scan-parallel-segments.js index 4a5294a..5452ce0 100644 --- a/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithScans/scan-parallel-segments.js +++ b/examples/SDK/node.js/sdk_v3/data_plane/WorkingWithScans/scan-parallel-segments.js @@ -1,28 +1,27 @@ -const AWS = require("aws-sdk"); +const { DynamoDBClient } = require("@aws-sdk/client-dynamodb"); +const { DynamoDBDocumentClient, ScanCommand } = require("@aws-sdk/lib-dynamodb"); -AWS.config.update({ region: "us-west-2" }); - -const documentClient = new AWS.DynamoDB.DocumentClient(); +const client = new DynamoDBClient({ region: "us-west-2" }); +const documentClient = DynamoDBDocumentClient.from(client); const segments = 5; // Define a total number segments to scan across, and execute multiple table scans asynchronously. async function parallelScan(segments = 1) { let results = []; for (let i = 0; i < segments; i++) { - let scan = documentClient - .scan({ - TableName: "Products", - FilterExpression: "#status = :status", - ExpressionAttributeNames: { - "#status": "ProductStatus", - }, - ExpressionAttributeValues: { - ":status": "IN_STOCK", - }, - TotalSegments: segments, // The total number of segments to scan across, in this case 5. - Segment: i, // The segment index for this particular query, zero indexed, in this case 0-4. - }) - .promise(); + const command = new ScanCommand({ + TableName: "Products", + FilterExpression: "#status = :status", + ExpressionAttributeNames: { + "#status": "ProductStatus", + }, + ExpressionAttributeValues: { + ":status": "IN_STOCK", + }, + TotalSegments: segments, // The total number of segments to scan across, in this case 5. + Segment: i, // The segment index for this particular query, zero indexed, in this case 0-4. + }); + let scan = documentClient.send(command); // Push unsettled scan Promise into results array. results.push(scan); } diff --git a/scripts/nosqlworkbenchscript/create-workbench-import.js b/scripts/nosqlworkbenchscript/create-workbench-import.js index db7ada1..ea15cfa 100644 --- a/scripts/nosqlworkbenchscript/create-workbench-import.js +++ b/scripts/nosqlworkbenchscript/create-workbench-import.js @@ -9,10 +9,12 @@ // node generateModel.js CustomerData >CustomerData.json // -const AWS = require('aws-sdk'); -AWS.config.region = process.env.AWS_REGION || 'us-west-2'; - -// AWS.config.endpoint = 'http://localhost:8000'; +const { DynamoDBClient, DescribeTableCommand, ScanCommand } = require('@aws-sdk/client-dynamodb'); + +const dynamodb = new DynamoDBClient({ + region: process.env.AWS_REGION || 'us-west-2' + // endpoint: 'http://localhost:8000' // Uncomment for local DynamoDB +}); const DYNAMODB_TABLE = process.argv.length > 2 ? process.argv.slice(2)[0] : 'Customer360'; @@ -32,7 +34,7 @@ const ModelMetadata = { "Version": "2.0" }; -const dynamodb = new AWS.DynamoDB(); + const buildModel = (err, data) => { @@ -173,9 +175,11 @@ const buildModel = (err, data) => { }; - dynamodb.scan({TableName:DYNAMODB_TABLE}, buildItemData); + const scanCommand = new ScanCommand({TableName: DYNAMODB_TABLE}); + dynamodb.send(scanCommand).then(buildItemData).catch(buildItemData); }; -dynamodb.describeTable({TableName:DYNAMODB_TABLE}, buildModel); +const describeCommand = new DescribeTableCommand({TableName: DYNAMODB_TABLE}); +dynamodb.send(describeCommand).then(buildModel).catch(buildModel);