0
votes

I'm using CDK (Typescript) to enable DDB autoscaling for existing table. I'm trying to call an autoScaleReadCapacity method to a imported table object.

 const importedtable = Table.fromTableArn(this, 'ImportedTable', 'arn:aws:dynamodb:us-west-2:011111:table/Testing-FE');
        importedtable.
        //config Autoscaling
        importedtable.autoScaleReadCapacity({
            minCapacity: 10                 
            maxCapacity: 10
                
        })

But getting error as

error TS2339: Property 'autoScaleReadCapacity' does not exist on type 'ITable'

Any clue on how to set auto scale properties for already created DDB table.

1
You can do any modification in the table properties in the imported table. You need to add auto scaling configuration in the stack from which table is created. - nirvana124
Yes. What i am trying to do is same on imported table i am trying to call autoscaleReadCapacity method. Is this approach wrong ? - Srikanth Rao

1 Answers

0
votes

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)
  }
}