我尝试运行S3 TransferManager示例。我有问题替换这些值。我不确定在哪里可以获得COGNITO_POOL_ID。当它运行时,我可以看到UI一秒钟,然后停止。我需要有人帮我指出如何在Constant类中找到COGNITO_POOL_ID和其他值。如果可能,请提供屏幕截图和网址。谢谢。
public class Constants {
public static final String AWS_ACCOUNT_ID = "########";
public static final String COGNITO_POOL_ID =
"Cognito_RTanahUnauth_DefaultRole";
public static final String COGNITO_ROLE_UNAUTH =
"rn:aws:iam::##########:role/Cognito_RTanahUnauth_DefaultRole";
public static final String BUCKET_NAME = "rtanah";
}
这是logcat消息
22 23:05:07.682 5718-5733/com.amazonaws.demo.s3_transfer_manager E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.amazonaws.demo.s3_transfer_manager, PID: 5718
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: com.amazonaws.AmazonServiceException: 1 validation error detected: Value 'Cognito_RTanahUnauth_DefaultRole' at 'identityPoolId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w-]+:[0-9a-f-]+ (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ValidationException; Request ID: 2fc575a2-baa4-11e4-a864-a7823d1dc7e2)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:820)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:439)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:245)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:1079)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getId(AmazonCognitoIdentityClient.java:361)
at com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.getIdentityId(AWSAbstractCognitoIdentityProvider.java:164)
at com.amazonaws.auth.AWSAbstractCognitoIdentityProvider.refresh(AWSAbstractCognitoIdentityProvider.java:307)
at com.amazonaws.auth.AWSBasicCognitoIdentityProvider.refresh(AWSBasicCognitoIdentityProvider.java:79)
at com.amazonaws.auth.CognitoCredentialsProvider.retryRefresh(CognitoCredentialsProvider.java:568)
at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:541)
at com.amazonaws.auth.CognitoCredentialsProvider.getCredentials(CognitoCredentialsProvider.java:366)
at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:447)
at com.amazonaws.auth.CognitoCachingCredentialsProvider.getCredentials(CognitoCachingCredentialsProvider.java:79)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3686)
at com.amazonaws.services.s3.AmazonS3Client.headBucket(AmazonS3Client.java:1030)
at com.amazonaws.services.s3.AmazonS3Client.doesBucketExist(AmazonS3Client.java:993)
at com.amazonaws.demo.s3_transfer_manager.Util.doesBucketExist(Util.java:68)
at com.amazonaws.demo.s3_transfer_manager.MainActivity$CheckBucketExists.doInBackground(MainActivity.java:223)
at com.amazonaws.demo.s3_transfer_manager.MainActivity$CheckBucketExists.doInBackground(MainActivity.java:218)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
答案 0 :(得分:4)
如果要创建标识池,可以转到Cognito console并单击新标识池。创建池后,它将为您提供一个具有标识池ID的示例代码。您可以直接在示例应用中使用此代码。有关创建标识池的更多信息,请阅读文档here。
如果您已有现有的标识池,请单击Cognito控制台中的代码浏览器,以获取要在示例应用中粘贴的代码。
答案 1 :(得分:0)
在AWS服务下导航到Cognito,单击您的身份池,然后在右上角单击"编辑身份池"。您的身份池ID将直接位于"身份池名称"。复制所有内容,然后将其粘贴到您的应用中。