I'm running a lambda function using the boto3 SDK in order to add autoscaling policies to a number of dynamoDB tables and indices, however it's consistently throwing this error:
An error occurred (ObjectNotFoundException) when calling the PutScalingPolicy operation: No scalable target registered for service namespace: dynamodb, resource ID: table/tableName, scalable dimension: dynamodb:table:ReadCapacityUnits: ObjectNotFoundException
Relevant code here:
def set_scaling_policy(resource_type, capacity_type, resource_id):
dbClient = boto3.client('application-autoscaling')
response = dbClient.put_scaling_policy(
PolicyName= 'dynamoDBScaling',
ServiceNamespace= 'dynamodb',
ResourceId= resource_id,
ScalableDimension= 'dynamodb:{0}:{1}CapacityUnits'.format(resource_type,capacity_type),
PolicyType='TargetTrackingScaling',
TargetTrackingScalingPolicyConfiguration={
'TargetValue': 50.0,
'PredefinedMetricSpecification': {
'PredefinedMetricType': 'DynamoDB{0}CapacityUtilization'.format(capacity_type)
}
}
)
(resource_type is either 'table' or 'index'; capacity_type is either 'Read' or 'Write')
A few solutions I've considered:
fixing permissions - it was having some permissions issues before, I gave it AmazonDynamoDBFullAccess, which seems to have fixed all that. Also, presumably it would throw a different error if it didn't have access
formatting of parameters - according to the API here, it all seems correct. I've tried variants like using the full ARN instead of table/tableName, using just tablename, etc.
checking that tableName actually exists - it does, and I can add and remove scaling policies via the AWS console just fine