@@ -13,6 +13,10 @@ import DynamoDB, {
1313 TableNameList ,
1414 ListTablesInput ,
1515 ContinuousBackupsDescription ,
16+ DescribeTableReplicaAutoScalingOutput ,
17+ TableAutoScalingDescription ,
18+ ReplicaAutoScalingDescription ,
19+ ReplicaDescription ,
1620} from 'aws-sdk/clients/dynamodb'
1721import { Config } from 'aws-sdk/lib/config'
1822import { AWSError } from 'aws-sdk/lib/error'
@@ -31,11 +35,17 @@ const serviceName = 'DynamoDB'
3135const errorLog = new AwsErrorLog ( serviceName )
3236const endpoint = initTestEndpoint ( serviceName )
3337
34- export interface RawAwsDynamoDbTable extends TableDescription {
38+ export interface RawAwsReplicaDescription extends ReplicaDescription {
39+ AutoScaling ?: ReplicaAutoScalingDescription
40+ }
41+
42+ export interface RawAwsDynamoDbTable
43+ extends Omit < TableDescription , 'Replicas' > {
3544 region : string
3645 ttlEnabled ?: boolean
3746 pointInTimeRecoveryEnabled ?: boolean
3847 Tags ?: TagMap
48+ Replicas ?: RawAwsReplicaDescription [ ]
3949}
4050
4151const checkIfEnabled = ( status : string ) : boolean =>
@@ -220,6 +230,30 @@ const getTableBackupsDescription = async (
220230 )
221231 } )
222232
233+ const getTableReplicaAutoScaling = async (
234+ dynamoDb : DynamoDB ,
235+ tableName : TableName
236+ ) : Promise < TableAutoScalingDescription > =>
237+ new Promise ( resolve => {
238+ dynamoDb . describeTableReplicaAutoScaling (
239+ {
240+ TableName : tableName ,
241+ } ,
242+ ( err : AWSError , data : DescribeTableReplicaAutoScalingOutput ) => {
243+ if ( err ) {
244+ errorLog . generateAwsErrorLog ( {
245+ functionName : 'dynamodb:describeTableReplicaAutoScaling' ,
246+ err,
247+ } )
248+ }
249+ if ( ! isEmpty ( data ) ) {
250+ resolve ( data . TableAutoScalingDescription )
251+ }
252+ resolve ( { } )
253+ }
254+ )
255+ } )
256+
223257export default async ( {
224258 regions,
225259 config,
@@ -235,6 +269,7 @@ export default async ({
235269 const tagsPromises = [ ]
236270 const ttlInfoPromises = [ ]
237271 const backupInfoPromises = [ ]
272+ const tableReplicaAutoScalingPromises = [ ]
238273
239274 // First we get all table name for all regions
240275 regions . split ( ',' ) . map ( region => {
@@ -306,7 +341,7 @@ export default async ({
306341 logger . debug ( lt . gettingTableTtlInfo )
307342 await Promise . all ( ttlInfoPromises )
308343
309- // Finally we get the backup information for each table
344+ // Get the backup information for each table
310345 tableData . map ( ( { TableName, region } , idx ) => {
311346 const dynamoDb = new DynamoDB ( { ...config , region, endpoint } )
312347 const backupInfoPromise = new Promise < void > ( async resolveBackupInfo => {
@@ -320,6 +355,36 @@ export default async ({
320355 } )
321356 logger . debug ( lt . gettingTableBackupInfo )
322357 await Promise . all ( backupInfoPromises )
358+
359+ // Finally we get the auto scaling settings for each table
360+ tableData . map ( ( { TableName : tableName , region } , idx ) => {
361+ const dynamoDb = new DynamoDB ( { ...config , region, endpoint } )
362+ const tableReplicaAutoScalingPromise = new Promise < void > (
363+ async resolveTableReplicaAutoScaling => {
364+ const globalSettings : TableAutoScalingDescription =
365+ await getTableReplicaAutoScaling ( dynamoDb , tableName )
366+ tableData [ idx ] . Replicas = tableData [ idx ] . Replicas ?. map (
367+ ( { RegionName : regionName , ...rest } ) => {
368+ const autoScaling : ReplicaAutoScalingDescription =
369+ globalSettings ?. Replicas ?. find (
370+ r => r . RegionName === regionName
371+ ) || { }
372+ return {
373+ AutoScaling : autoScaling ,
374+ RegionName : regionName ,
375+ ...rest ,
376+ }
377+ }
378+ )
379+ resolveTableReplicaAutoScaling ( )
380+ }
381+ )
382+ tableReplicaAutoScalingPromises . push ( tableReplicaAutoScalingPromise )
383+ } )
384+
385+ logger . debug ( lt . gettingTableBackupInfo )
386+ await Promise . all ( tableReplicaAutoScalingPromises )
387+
323388 errorLog . reset ( )
324389
325390 resolve ( groupBy ( tableData , 'region' ) )
0 commit comments