Last active
August 29, 2015 14:05
-
-
Save yuta-imai/f2acb5a013e568417747 to your computer and use it in GitHub Desktop.
The sample code for using CognitoIndentityCredentials to retrieve AWS Credentials.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//現状CognitoはUS_EAST_1にしか無いので一度こちらを設定 | |
AWS.config.region = 'us-east-1'; | |
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ | |
AccountId: 'YOUR_AWS_ACCOUNT_ID', | |
IdentityPoolId: 'COGNITO_IDENTITIY_POOL_ID', | |
RoleArn: 'IAM_ROLE_ARN' | |
}); | |
//その後、利用したいリージョンに設定を変更 | |
AWS.config.region = 'ap-northeast-1'; | |
//あとは好きなコードを書く | |
//例えばDynamoDBのテーブルをスキャンする | |
var dynamodb = new AWS.DynamoDB(); | |
dynamodb.scan({ | |
TableName: 'TABLENAME' | |
},function(err,data){ | |
if(err) console.log(err); | |
else console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment