AWS Code Sample
Catalog

cognito_getcreds.html

<!-- Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // Licensed under the Apache-2.0 License on an "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND. // ABOUT THIS BROWSER SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at // https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/browser-cognito-browser-creds.html --> <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Amazon Cognito Credenials Example</title> <meta charset="utf-8"> <script src="https://sdk.amazonaws.com/js/aws-sdk-2.244.1.min.js"></script> </head> <body> <div id="results">data</div> <script type="application/javascript"> // Set your needed values var IDENTITY_POOL_ID = 'Your Cognito identity pool ID'; var ACCOUNT_ID = 'Your AWS account ID'; var REGION = 'Your AWS region'; // Initialize the Amazon Cognito credentials provider AWS.config.region = REGION; // Region AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: IDENTITY_POOL_ID,}); var getIdParams = { IdentityPoolId: IDENTITY_POOL_ID, AccountId: ACCOUNT_ID }; var cognitoidentity = new AWS.CognitoIdentity({apiVersion: '2014-06-30'}); cognitoidentity.getId(getIdParams, function(err, data) { if (err) { results.innerHTML = "Error" + err; } else { results.innerHTML = "Cognito Identity ID is " + data.IdentityId; } }); </script> </body> </html>