A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/aws-samples/aws-sdk-js-v3-workshop below:

aws-samples/aws-sdk-js-v3-workshop: Sample application with instructions and examples for "Hands-on workshop with AWS JavaScript SDK v3"

If you're looking for scripts to upgrade your code from v2 to v3, see aws-sdk-js-codemod.

In this workshop, we're going to:

The note taking application is the modified version from the original Open Source MIT licensed project shared in the tutorials on serverless-stack.

If you are starting a new project with AWS SDK for JavaScript v3, then please refer aws-sdk-js-notes-app which uses more services in addition to S3 and DynamoDB.

To set up this workshop package, complete the following tasks:

This exercise code uses AWS SDK for JavaScript v2 as follows:

The README files have instructions on how to move both to v3. The backend and frontend can be worked on independently as long as the APIs don't change.

Migrate backend from v2 to v3

Follow backend README.md.

Migrate frontend from v2 to v3

Follow frontend README.md.

The Cloudformation stack can be deleted by running: yarn cdk destroy

This exercise has the code which uses AWS SDK for JavaScript v3, which you would have got after finishing Exercise1:

Edit existing APIs or create new ones to use AWS Services you're familiar with in the backend. For example:

Inspect the differences of stack trace if call DynamoDB.putItem with invalid resources in V2 and V3 SDK.

Using v2, call a service with invalid parameters as shown below:

Code
const DynamoDB = require("aws-sdk/clients/dynamodb");
const client = new DynamoDB({ region: "us-west-2" });
const request = client.putItem({
  TableName: "FakeName",
  Item: {
    Foo: { S: "Foo" },
  },
});
request.send((err, data) => {
  console.log(err);
});

When the code fails, the stack trace would look like:

Stack trace
ResourceNotFoundException: Requested resource not found
    at Request.extractError (XXX/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.callListeners (XXX/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (XXX/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (XXX/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (XXX/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (XXX/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at XXX/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:685:12)
    at AcceptorStateMachine.runTo (XXX/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at XXX/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:685:12)
    at AcceptorStateMachine.runTo (XXX/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at XXX/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (XXX/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (XXX/node_modules/aws-sdk/lib/sequential_executor.js:116:18)

This happens, as Request.transition exists multiple times as the SDK state machine stuck at some state and makes stack trace unreadable.

Is the same operation is tried in v3:

Code
const {
  DynamoDBClient,
  PutItemCommand,
} = require("@aws-sdk/client-dynamodb-node");
const client = new DynamoDBClient({ region: "us-west-2" });
const command = new PutItemCommand({
  TableName: "FakeName",
  Item: {
    Foo: { S: "Foo" },
  },
});
(async () => {
  try {
    await client.send(command);
  } catch (e) {
    console.log(e);
    throw e;
  }
})();

The stack trace would be much smaller:

Stack trace
ResourceNotFoundException: Requested resource not found
    at JsonRpcParser.exports.jsonErrorUnmarshaller [as parseServiceException] (XXX/node_modules/@aws-sdk/json-error-unmarshaller/build/index.js:37:70)
    at JsonRpcParser.<anonymous> (XXX/node_modules/@aws-sdk/protocol-json-rpc/build/JsonRpcParser.js:22:40)
    at step (XXX/node_modules/tslib/tslib.js:136:27)
    at Object.next (XXX/node_modules/tslib/tslib.js:117:57)
    at fulfilled (XXX/node_modules/tslib/tslib.js:107:62)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Contributions are more than welcome. Please read the code of conduct and the contributing guidelines.

This sample code is made available under the MIT license. See the LICENSE file.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4