1
votes

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

1

1 Answers

1
votes

put_scaling_policy

http://boto3.readthedocs.io/en/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.put_scaling_policy

You cannot create a scaling policy until you register the scalable target using RegisterScalableTarget

register_scalable_target

http://boto3.readthedocs.io/en/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.register_scalable_target

Registers or updates a scalable target. A scalable target is a resource that Application Auto Scaling can scale out or scale in. After you have registered a scalable target, you can use this operation to update the minimum and maximum values for its scalable dimension.