在我的 Android 应用程序中,我想为 AWS 创建临时凭证,这样我就不必在我的应用程序中存储我的秘密 AWS 凭证。我使用此代码创建凭据:
CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(), // get the context for the current activity
"XXXXXXXXXX",
"us-east-1:XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"arn:aws:iam::XXXXXXXXXXX:role/myUnauthRole",
"arn:aws:iam::XXXXXXXXXXX:role:role/myAuthRole",
Regions.US_EAST_1
);
AWSCredentials awsCredentials = new BasicAWSCredentials(cognitoProvider.getCredentials().getAWSAccessKeyId(), cognitoProvider.getCredentials().getAWSSecretKey());
当我这样尝试时,我的代码的最后一行出现错误,并带有 error "Not authorized to perform sts:AssumeRoleWithWeb Identity"
。我认为我用于myUnauthRole
和的策略存在问题myAuthRole
。它看起来像这样:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "sts:GetFederationToken",
"Resource": "*"
}]
}
在政策范围内我还有什么需要做的吗?我无法在互联网上为我的用例找到一个工作示例。在这里得到一些支持会很棒。
谢谢!