Your approach is fine but Current implementation for Imported table in CDK is not supporting it.
When you import a table it returns an object of type ITable but autoScaleReadCapacity and autoScaleWriteCapacity methods are declared and implemented inside Table class.
You can use below code as workaround and open a issue in AWS CDK repository.
import { Construct, Stack } from '@aws-cdk/core';
import { BaseScalableAttribute, BaseScalableAttributeProps, ServiceNamespace } from '@aws-cdk/aws-applicationautoscaling';
import { Role } from '@aws-cdk/aws-iam';
import { Table } from '@aws-cdk/aws-dynamodb';
const table = Table.fromTableName(this, 'MyTable', 'MyTable');
const scalingRole = Role.fromRoleArn(this, 'ScalingRole', Stack.of(this).formatArn({
service: 'iam',
region: '',
resource: 'role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com',
resourceName: 'AWSServiceRoleForApplicationAutoScaling_DynamoDBTable',
}));
new ScalableTableAttribute(this, 'ReadScaling', {
serviceNamespace: ServiceNamespace.DYNAMODB,
resourceId: `table/${table.tableName}`,
dimension: 'dynamodb:table:ReadCapacityUnits', //dimension: 'dynamodb:table:WriteCapacityUnits',
role: scalingRole,
maxCapacity: 10,
minCapacity: 10
})
export class ScalableTableAttribute extends BaseScalableAttribute {
constructor(scope: Construct, id: string, props: BaseScalableAttributeProps) {
super(scope, id, props)
}
}