I have a table with some elements. I am trying to use Fine-Grained Access Control (Limit Access to Specific Attributes in a Table) on unauth (I want to return specific attributes to user who are not authenticated yet) role where user scan on specific attributes based on following url Using IAM Policy Conditions for Fine-Grained Access Control.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "LimitAccessToSpecificAttributes",
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:Query",
"dynamodb:BatchGetItem",
"dynamodb:Scan"
],
"Resource": [
"arn:aws:dynamodb:us-west-2:AccountID:table/MyTable"
],
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:Attributes": [
"startDate",
"endDate"
]
},
"StringEqualsIfExists": {
"dynamodb:Select": "SPECIFIC_ATTRIBUTES",
"dynamodb:ReturnValues": [
"NONE",
"UPDATED_OLD",
"UPDATED_NEW"
]
}
}
}
]
}
When I am removing following role it works:
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:Attributes": [
"startDate",
"endDate"
]
},
"StringEqualsIfExists": {
"dynamodb:Select": "SPECIFIC_ATTRIBUTES",
"dynamodb:ReturnValues": [
"NONE",
"UPDATED_OLD",
"UPDATED_NEW"
]
}
The problem is that when I am running my code (android) I am getting following exception:
User: arn:aws:sts::AccountID:assumed-role/Cognito_XXXUnauth_Role/CognitoIdentityCredentials is not authorized to perform: dynamodb:Scan on resource: arn:aws:dynamodb:us-east-1:AccountID:table/MyTable (Service: AmazonDynamoDB; Status Code: 400; Error Code: AccessDeniedException;
I would like to know what I am doing wrong which causes the exception. Is there any other way to get specific attributes?
I am using following android code:
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(getApplicationContext(),
"identityPoolId",
Regions.US_EAST_1
);
AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentialsProvider);
ScanRequest scanRequest = new ScanRequest();
scanRequest = scanRequest.withProjectionExpression("startDate, endDate");
scanRequest.setTableName("MyTable");
try {
ScanResult scanResult = ddb.scan(scanRequest);
} catch (Exception ex) {
log(ex.getMessage());
}
Any help would be appreciated.