https://docs.aws.amazon.com/general/latest/gr/Welcome.html
Contents:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/welcome.html
For Node.js (EC2, Lambda), for browser. Amplify extends SDK for browser and provides declarative interface.
Node.js:
Browser:
Minimum - region & credentials (note: if load from user shared config, credentials could be null if resume role, it only become available after actually used)
How to configure:
# from shellexport AWS_SDK_LOAD_CONFIG=trueexport AWS_PROFILE=default# also AWS_REGION # see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-region.html# see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.htmlor
process.env.AWS_SDK_LOAD_CONFIG = true; const AWS = require('aws-sdk');Examples: using cognito ID pool
AWS.config.region = ...// from cognito ID poolAWS.config.credentials = new AWS.CognitoIdentityCredentials({...// another stylevar myCredentials = new AWS.CognitoIdentityCredentials({IdentityPoolId:'IDENTITY_POOL_ID'});var myConfig = new AWS.Config({ credentials: myCredentials, region: 'us-west-2'});// using 'update' myConfig = new AWS.Config();myConfig.update({region: 'us-east-1'});Example: per-service instance
var ec2_regionA = new AWS.EC2({region: 'ap-southeast-2', maxRetries: 15, apiVersion: '2014-10-01'});var ec2_regionB = new AWS.EC2({region: 'us-east-1', maxRetries: 15, apiVersion: '2014-10-01'});API version identified by 'YYYY-MM-DD'
Locking up recommended in production environment.
To lockup, do it individually when instantiating service object, or globally:
AWS.config.apiVersions = { dynamodb: '2011-12-05', ec2: '2013-02-01', redshift: 'latest'};Importing the service class:
Creating service object:
Invoking a service include full request / response & retry
AWS.Request / AWS.Response object encapsulates the request & responses.
Logging - see document
Asynchronous calling
Response Object
See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#retryDelayOptions-property
Someone said most services by default retry 3 times, while DynamoDB retry 10 times (can be set).
Set maximum retries globally: AWS.config.maxRetries = 5
Set for individual service (DynamoDB): new AWS.DynamoDB({maxRetries: 5})
Inspect & diagnose:
On global level
AWS.events.on('retry', function(resp) { if (resp.error && resp.error.retryable) { var date = new Date(); console.log(date, '| Retrying request for the ' + resp.retryCount + 'th time.'); console.log(date, '| Retry triggered by', err.code, err.message); }}); On individual request level
req.on('retry', function() { ... });