我正在使用CDK (Typescript)为现有的表启用DDB自动缩放。我正在尝试调用一个导入的表对象的autoScaleReadCapacity方法。
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
})但是得到的错误是
error TS2339: Property 'autoScaleReadCapacity' does not exist on type 'ITable'有关如何为已创建的DDB表设置自动缩放属性的任何线索。
发布于 2021-03-24 17:35:17
您的方法很好,但是当前在CDK中对导入表的实现不支持它。
当您导入一个表时,它返回一个ITable类型的对象,但是autoScaleReadCapacity和autoScaleWriteCapacity方法是在Table类中声明和实现的。
您可以使用以下代码作为变通方法,并在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)
}
}https://stackoverflow.com/questions/66766388
复制相似问题