cognito_getcreds.html - AWS Code Sample


cognito_getcreds.html demonstrates how to obtain credentials

<!-- * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. --> <!-- --> <!-- ABOUT THIS BROWSER SAMPLE: This sample is related to the SDK for JavaScript Developer Guide at // --> <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Amazon Cognito Credentials Example</title> <meta charset="utf-8"> <script src=""></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>

Sample Details

Service: Amazon Cognito

Last tested:

Author: AWS-JSDG

Type: full-example