Mr. N.V.Rao
Mr. N.V.Rao

Reputation: 1082

AWS S3 accountId failed to satisfy constraint : Error Code 400 ValidationException

Hi all,

I am using AWS S3 SDK 2.2.8 for Image uploading to S3. I have created Bucket in S3 console.

I am using following snippet code to upload a file.

String AWS_ACC_ID="XXXX-XXXX-XXX";
String AWS_POOL_ID="us-east-1:XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX";
String AWS_UNAUTH_ROLE="arn:aws:iam:XXXXXXX";
String AWS_AUTH_ROLE="arn:aws:iam:XXXXXXX";   

AWSCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                            context, AWS_ACC_ID,
                            AWS_POOL_ID, AWS_UNAUTH_ROLE,
                            AWS_AUTH_ROLE, Regions.US_EAST_1);        

AmazonS3 s3Client = new AmazonS3Client(credentialsProvider);

PutObjectRequest putRequest = new PutObjectRequest(
                        AwsCredentials.AWS_BUCKET_NAME,
                        folderPath + file.getName(), file)
                        .withCannedAcl(CannedAccessControlList.PublicRead);

s3Client.putObject(putRequest);

I'm getting following exception:

com.amazonaws.AmazonServiceException: 1 validation error detected: Value 'XXXX-XXXX-XXXX' at 'accountId' failed to satisfy constraint: Member must satisfy regular expression pattern: \d+ (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ValidationException; Request ID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX)

But when I am using old AWS SDK I can able to upload the files to S3.

Upvotes: 0

Views: 2878

Answers (2)

AlexeyVMP
AlexeyVMP

Reputation: 2426

Just pass null as accountId in the service constructor

Upvotes: 0

Yangfan
Yangfan

Reputation: 1876

The account id consists of numbers only. Please remove the dashes.

On the other side, CognitoCachingCredentialsProvider doesn't require your account id any more. It has a simplified constructor which takes only your Cognito pool id and region. See this blog Sync store access and simplified credentials provider for more details.

Upvotes: 1

Related Questions