1
public static void main(String[] args) {
AmazonCognitoIdentity identityClient = new AmazonCognitoIdentityClient(new AnonymousAWSCredentials());
identityClient.setEndpoint("cognito-identity.us-east-1.amazonaws.com");
identityClient.setRegion(Region.getRegion(Regions.US_EAST_1));
GetIdRequest idRequest = new GetIdRequest();
idRequest.setAccountId("XXXXXXXXX");
idRequest.setIdentityPoolId("XXXXXXX");
GetIdResult idResp = identityClient.getId(idRequest);
String identityId = idResp.getIdentityId();
GetOpenIdTokenRequest tokenRequest = new GetOpenIdTokenRequest();
tokenRequest.setIdentityId(identityId);
GetOpenIdTokenResult tokenResp = identityClient.getOpenIdToken(tokenRequest);
String openIdToken = tokenResp.getToken();
AWSSecurityTokenService stsClient = new AWSSecurityTokenServiceClient(new AnonymousAWSCredentials());
AssumeRoleWithWebIdentityRequest stsReq = new AssumeRoleWithWebIdentityRequest();
stsReq.setRoleArn(
"arn:aws:cognito-identity:us-east-1:XXXXXX:identitypool/us-east-1:XXXXXXX");
stsReq.setWebIdentityToken(openIdToken);
stsReq.setRoleSessionName("AppTestSession");
AssumeRoleWithWebIdentityResult stsResp = stsClient.assumeRoleWithWebIdentity(stsReq);
Credentials stsCredentials = stsResp.getCredentials();
AWSSessionCredentials sessionCredentials = new BasicSessionCredentials(stsCredentials.getAccessKeyId(),
stsCredentials.getSecretAccessKey(), stsCredentials.getSessionToken());
Date sessionCredentialsExpiration = stsCredentials.getExpiration();
System.out.println("session credentials expiration -> " + sessionCredentialsExpiration);
String bucketName = "s3fileupload";
String keyName = "cognitokey";
String uploadFileName = "/home/fresher/Downloads/say-hello.jpg";
AmazonS3 s3client = new AmazonS3Client(sessionCredentials);
s3client.setEndpoint("s3fileupload.s3-website-us-west-2.amazonaws.com");
File file = new File(uploadFileName);
s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
}
「ARNが無効です」という例外が表示されています。 これで私を案内してもらえますか?ファイルをs3にアップロード中のAWS Cognito例外
要求ARNは(:;:400;エラーコード:ValidationErrorを、IDを要求します:ステータスコードAWSSecurityTokenServiceサービスXXXXXXXXXXXXXXXXXX)無効であるあなたのSTSで