Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Last active August 29, 2015 14:05
Show Gist options
  • Save yuta-imai/f2acb5a013e568417747 to your computer and use it in GitHub Desktop.
Save yuta-imai/f2acb5a013e568417747 to your computer and use it in GitHub Desktop.
The sample code for using CognitoIndentityCredentials to retrieve AWS Credentials.
//現状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