AWS SDK for Javascript Developer Guide for SDK V2 AWS SDK for Javascript Developer Guide for SDK V2
Total Page:16
File Type:pdf, Size:1020Kb
AWS SDK for JavaScript Developer Guide for SDK v2 AWS SDK for JavaScript Developer Guide for SDK v2 AWS SDK for JavaScript: Developer Guide for SDK v2 Copyright © Amazon Web Services, Inc. and/or its affiliates. All rights reserved. Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon. AWS SDK for JavaScript Developer Guide for SDK v2 Table of Contents ...................................................................................................................................................... vii What Is the AWS SDK for JavaScript? ................................................................................................... 1 Maintenance and support for SDK major versions .......................................................................... 1 Using the SDK with Node.js ......................................................................................................... 1 Using the SDK with AWS Cloud9 .................................................................................................. 1 Using the SDK with AWS Amplify ................................................................................................. 2 Using the SDK with Web Browsers ............................................................................................... 2 Common Use Cases ............................................................................................................ 2 About the Examples ........................................................................................................... 2 Getting Started .................................................................................................................................. 3 Getting Started in a Browser Script .............................................................................................. 3 The Scenario ..................................................................................................................... 3 Step 1: Create an Amazon Cognito Identity Pool .................................................................... 4 Step 2: Add a Policy to the Created IAM Role ........................................................................ 4 Step 3: Create the HTML Page ............................................................................................. 5 Step 4: Write the Browser Script .......................................................................................... 5 Step 5: Run the Sample ...................................................................................................... 7 Full Sample ....................................................................................................................... 7 Possible Enhancements ....................................................................................................... 8 Getting Started in Node.js ........................................................................................................... 8 The Scenario ..................................................................................................................... 8 Prerequisite Tasks ............................................................................................................... 8 Step 1: Install the SDK and Dependencies ............................................................................. 9 Step 2: Configure Your Credentials ....................................................................................... 9 Step 3: Create the Package JSON for the Project .................................................................. 10 Step 4: Write the Node.js Code .......................................................................................... 10 Step 5: Run the Sample .................................................................................................... 11 Using AWS Cloud9 with the SDK for JavaScript .................................................................................... 12 Step 1: Set up Your AWS Account to Use AWS Cloud9 ................................................................... 12 Step 2: Set up Your AWS Cloud9 Development Environment .......................................................... 12 Step 3: Set up the SDK for JavaScript ......................................................................................... 13 To set up the SDK for JavaScript for Node.js ........................................................................ 13 To set up the SDK for JavaScript in the browser ................................................................... 13 Step 4: Download Example Code ................................................................................................ 13 Step 5: Run and Debug Example Code ........................................................................................ 14 Setting Up the SDK for JavaScript ...................................................................................................... 15 Prerequisites ............................................................................................................................ 15 Setting Up an AWS Node.js Environment ............................................................................. 15 Web Browsers Supported .................................................................................................. 16 Installing the SDK .................................................................................................................... 16 Installing Using Bower ...................................................................................................... 17 Loading the SDK ...................................................................................................................... 17 Upgrading From Version 1 ......................................................................................................... 18 Automatic Conversion of Base64 and Timestamp Types on Input/Output ................................. 18 Moved response.data.RequestId to response.requestId .......................................................... 18 Exposed Wrapper Elements ............................................................................................... 19 Dropped Client Properties ................................................................................................. 21 Configuring the SDK for JavaScript ..................................................................................................... 23 Using the Global Configuration Object ........................................................................................ 23 Setting Global Configuration ............................................................................................. 23 Setting Configuration Per Service ....................................................................................... 25 Immutable Configuration Data ........................................................................................... 25 Setting the AWS Region ............................................................................................................ 25 In a Client Class Constructor .............................................................................................. 25 iii AWS SDK for JavaScript Developer Guide for SDK v2 Using the Global Configuration Object ................................................................................ 26 Using an Environment Variable .......................................................................................... 26 Using a Shared Config File ................................................................................................ 26 Order of Precedence for Setting the Region ......................................................................... 26 Specifying Custom Endpoints ..................................................................................................... 27 Endpoint String Format ..................................................................................................... 27 Endpoints for the ap-northeast-3 Region ............................................................................ 27 Endpoints for MediaConvert .............................................................................................. 27 Getting Your Credentials ........................................................................................................... 27 Setting Credentials ................................................................................................................... 28 Best Practices for Credentials ............................................................................................. 29 Setting Credentials in Node.js ............................................................................................ 29 Setting Credentials in a Web Browser ................................................................................. 32 Locking API Versions ................................................................................................................. 39 Getting API Versions ........................................................................................................