AWS SDK for JavaScript Developer Guide for SDK v2
Order of Precedence for Setting the Region ......................................................................... 23
Specifying Custom Endpoints ..................................................................................................... 23
Endpoint String Format ..................................................................................................... 23
Endpoints for the ap-northeast-3 Region ............................................................................ 23
Endpoints for MediaConvert .............................................................................................. 24
Getting Your Credentials ........................................................................................................... 24
Setting Credentials ................................................................................................................... 25
Best Practices for Credentials ............................................................................................. 25
Setting Credentials in Node.js ............................................................................................ 25
Setting Credentials in a Web Browser ................................................................................. 28
Locking API Versions ................................................................................................................. 34
Node.js Considerations .............................................................................................................. 35
Using Built-In Node.js Modules ........................................................................................... 35
Using NPM Packages ........................................................................................................ 35
Configuring maxSockets in Node.js ..................................................................................... 36
Configuring Proxies for Node.js .......................................................................................... 36
Registering Certificate Bundles in Node.js ............................................................................ 37
Browser Script Considerations .................................................................................................... 37
Building the SDK for Browsers ........................................................................................... 37
Cross-Origin Resource Sharing (CORS) ................................................................................. 40
Bundling with Webpack ............................................................................................................ 42
Installing Webpack ........................................................................................................... 42
Configuring Webpack ........................................................................................................ 43
Running Webpack ............................................................................................................ 43
Using the Webpack Bundle ................................................................................................ 44
Importing Individual Services ............................................................................................. 44
Bundling for Node.js ......................................................................................................... 45
Working with Services ....................................................................................................................... 47
Creating and Calling Service Objects ........................................................................................... 47
Requiring Individual Services ............................................................................................. 48
Creating Service Objects ................................................................................................... 49
Locking the API Version of a Service Object ......................................................................... 49
Specifying Service Object Parameters ................................................................................. 49
Logging AWS SDK for JavaScript Calls ........................................................................................ 50
Using a Third-Party Logger ................................................................................................ 50
Calling Services Asychronously ................................................................................................... 51
Managing Asychronous Calls .............................................................................................. 51
Using a Callback Function ................................................................................................. 52
Using a Request Object Event Listener ................................................................................ 53
Using Promises ................................................................................................................ 57
Requests With a Node.js Stream Object .............................................................................. 58
Using the Response Object ........................................................................................................ 59
Accessing Data Returned in the Response Object .................................................................. 59
Paging Through Returned Data .......................................................................................... 60
Accessing Error Information from a Response Object ............................................................ 60
Accessing the Originating Request Object ............................................................................ 60
Working with JSON .................................................................................................................. 60
JSON as Service Object Parameters .................................................................................... 61
Returning Data as JSON .................................................................................................... 62
SDK for JavaScript Code Examples ..................................................................................................... 63
Amazon CloudWatch Examples .................................................................................................. 63
Creating Alarms in Amazon CloudWatch .............................................................................. 64
Using Alarm Actions in Amazon CloudWatch ........................................................................ 67
Getting Metrics from Amazon CloudWatch .......................................................................... 69
Sending Events to Amazon CloudWatch Events .................................................................... 72
Using Subscription Filters in Amazon CloudWatch Logs ......................................................... 75
Amazon DynamoDB Examples .................................................................................................... 79
iv