@stacksjs/ts-cloud 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +321 -0
  3. package/bin/cli.ts +133 -0
  4. package/bin/commands/analytics.ts +328 -0
  5. package/bin/commands/api.ts +379 -0
  6. package/bin/commands/assets.ts +221 -0
  7. package/bin/commands/audit.ts +501 -0
  8. package/bin/commands/backup.ts +682 -0
  9. package/bin/commands/cache.ts +294 -0
  10. package/bin/commands/cdn.ts +281 -0
  11. package/bin/commands/config.ts +202 -0
  12. package/bin/commands/container.ts +105 -0
  13. package/bin/commands/cost.ts +208 -0
  14. package/bin/commands/database.ts +401 -0
  15. package/bin/commands/deploy.ts +674 -0
  16. package/bin/commands/domain.ts +397 -0
  17. package/bin/commands/email.ts +423 -0
  18. package/bin/commands/environment.ts +285 -0
  19. package/bin/commands/events.ts +424 -0
  20. package/bin/commands/firewall.ts +145 -0
  21. package/bin/commands/function.ts +116 -0
  22. package/bin/commands/generate.ts +280 -0
  23. package/bin/commands/git.ts +139 -0
  24. package/bin/commands/iam.ts +464 -0
  25. package/bin/commands/index.ts +48 -0
  26. package/bin/commands/init.ts +120 -0
  27. package/bin/commands/logs.ts +148 -0
  28. package/bin/commands/network.ts +579 -0
  29. package/bin/commands/notify.ts +489 -0
  30. package/bin/commands/queue.ts +407 -0
  31. package/bin/commands/scheduler.ts +370 -0
  32. package/bin/commands/secrets.ts +54 -0
  33. package/bin/commands/server.ts +629 -0
  34. package/bin/commands/shared.ts +97 -0
  35. package/bin/commands/ssl.ts +138 -0
  36. package/bin/commands/stack.ts +325 -0
  37. package/bin/commands/status.ts +385 -0
  38. package/bin/commands/storage.ts +450 -0
  39. package/bin/commands/team.ts +96 -0
  40. package/bin/commands/tunnel.ts +489 -0
  41. package/bin/commands/utils.ts +202 -0
  42. package/build.ts +15 -0
  43. package/cloud +2 -0
  44. package/package.json +99 -0
  45. package/src/aws/acm.ts +768 -0
  46. package/src/aws/application-autoscaling.ts +845 -0
  47. package/src/aws/bedrock.ts +4074 -0
  48. package/src/aws/client.ts +878 -0
  49. package/src/aws/cloudformation.ts +896 -0
  50. package/src/aws/cloudfront.ts +1531 -0
  51. package/src/aws/cloudwatch-logs.ts +154 -0
  52. package/src/aws/comprehend.ts +839 -0
  53. package/src/aws/connect.ts +1056 -0
  54. package/src/aws/deploy-imap.ts +384 -0
  55. package/src/aws/dynamodb.ts +340 -0
  56. package/src/aws/ec2.ts +1385 -0
  57. package/src/aws/ecr.ts +621 -0
  58. package/src/aws/ecs.ts +615 -0
  59. package/src/aws/elasticache.ts +301 -0
  60. package/src/aws/elbv2.ts +942 -0
  61. package/src/aws/email.ts +928 -0
  62. package/src/aws/eventbridge.ts +248 -0
  63. package/src/aws/iam.ts +1689 -0
  64. package/src/aws/imap-server.ts +2100 -0
  65. package/src/aws/index.ts +213 -0
  66. package/src/aws/kendra.ts +1097 -0
  67. package/src/aws/lambda.ts +786 -0
  68. package/src/aws/opensearch.ts +158 -0
  69. package/src/aws/personalize.ts +977 -0
  70. package/src/aws/polly.ts +559 -0
  71. package/src/aws/rds.ts +888 -0
  72. package/src/aws/rekognition.ts +846 -0
  73. package/src/aws/route53-domains.ts +359 -0
  74. package/src/aws/route53.ts +1046 -0
  75. package/src/aws/s3.ts +2318 -0
  76. package/src/aws/scheduler.ts +571 -0
  77. package/src/aws/secrets-manager.ts +769 -0
  78. package/src/aws/ses.ts +1081 -0
  79. package/src/aws/setup-phone.ts +104 -0
  80. package/src/aws/setup-sms.ts +580 -0
  81. package/src/aws/sms.ts +1735 -0
  82. package/src/aws/smtp-server.ts +531 -0
  83. package/src/aws/sns.ts +758 -0
  84. package/src/aws/sqs.ts +382 -0
  85. package/src/aws/ssm.ts +807 -0
  86. package/src/aws/sts.ts +92 -0
  87. package/src/aws/support.ts +391 -0
  88. package/src/aws/test-imap.ts +86 -0
  89. package/src/aws/textract.ts +780 -0
  90. package/src/aws/transcribe.ts +108 -0
  91. package/src/aws/translate.ts +641 -0
  92. package/src/aws/voice.ts +1379 -0
  93. package/src/config.ts +35 -0
  94. package/src/deploy/index.ts +7 -0
  95. package/src/deploy/static-site-external-dns.ts +906 -0
  96. package/src/deploy/static-site.ts +1125 -0
  97. package/src/dns/godaddy.ts +412 -0
  98. package/src/dns/index.ts +183 -0
  99. package/src/dns/porkbun.ts +362 -0
  100. package/src/dns/route53-adapter.ts +414 -0
  101. package/src/dns/types.ts +114 -0
  102. package/src/dns/validator.ts +369 -0
  103. package/src/generators/index.ts +5 -0
  104. package/src/generators/infrastructure.ts +1660 -0
  105. package/src/index.ts +163 -0
  106. package/src/push/apns.ts +452 -0
  107. package/src/push/fcm.ts +506 -0
  108. package/src/push/index.ts +58 -0
  109. package/src/ssl/acme-client.ts +478 -0
  110. package/src/ssl/index.ts +7 -0
  111. package/src/ssl/letsencrypt.ts +747 -0
  112. package/src/types.ts +2 -0
  113. package/src/utils/cli.ts +398 -0
  114. package/src/validation/index.ts +5 -0
  115. package/src/validation/template.ts +405 -0
  116. package/test/index.test.ts +128 -0
  117. package/tsconfig.json +18 -0
@@ -0,0 +1,845 @@
1
+ /**
2
+ * AWS Application Auto Scaling Client
3
+ * Supports auto-scaling for ECS services, DynamoDB tables, and other AWS resources
4
+ * Direct API calls without AWS CLI dependency
5
+ */
6
+
7
+ import { AWSClient } from './client'
8
+
9
+ export type ScalableDimension =
10
+ | 'ecs:service:DesiredCount'
11
+ | 'dynamodb:table:ReadCapacityUnits'
12
+ | 'dynamodb:table:WriteCapacityUnits'
13
+ | 'dynamodb:index:ReadCapacityUnits'
14
+ | 'dynamodb:index:WriteCapacityUnits'
15
+ | 'rds:cluster:ReadReplicaCount'
16
+ | 'lambda:function:ProvisionedConcurrency'
17
+ | 'elasticache:replication-group:NodeGroups'
18
+ | 'elasticache:replication-group:Replicas'
19
+
20
+ export type ServiceNamespace =
21
+ | 'ecs'
22
+ | 'dynamodb'
23
+ | 'rds'
24
+ | 'lambda'
25
+ | 'elasticache'
26
+ | 'custom-resource'
27
+ | 'comprehend'
28
+ | 'kafka'
29
+ | 'sagemaker'
30
+
31
+ export type MetricType =
32
+ | 'ECSServiceAverageCPUUtilization'
33
+ | 'ECSServiceAverageMemoryUtilization'
34
+ | 'ALBRequestCountPerTarget'
35
+ | 'DynamoDBReadCapacityUtilization'
36
+ | 'DynamoDBWriteCapacityUtilization'
37
+ | 'RDSReaderAverageCPUUtilization'
38
+ | 'RDSReaderAverageDatabaseConnections'
39
+ | 'EC2SpotFleetRequestAverageCPUUtilization'
40
+ | 'EC2SpotFleetRequestAverageNetworkIn'
41
+ | 'EC2SpotFleetRequestAverageNetworkOut'
42
+ | 'SageMakerVariantInvocationsPerInstance'
43
+ | 'SageMakerVariantProvisionedConcurrencyUtilization'
44
+ | 'ElastiCachePrimaryEngineCPUUtilization'
45
+ | 'ElastiCacheReplicaEngineCPUUtilization'
46
+ | 'ElastiCacheDatabaseMemoryUsageCountedForEvictPercentage'
47
+ | 'LambdaProvisionedConcurrencyUtilization'
48
+ | 'CassandraReadCapacityUtilization'
49
+ | 'CassandraWriteCapacityUtilization'
50
+
51
+ export interface ScalableTarget {
52
+ ServiceNamespace: ServiceNamespace
53
+ ResourceId: string
54
+ ScalableDimension: ScalableDimension
55
+ MinCapacity: number
56
+ MaxCapacity: number
57
+ RoleARN?: string
58
+ CreationTime?: string
59
+ SuspendedState?: {
60
+ DynamicScalingInSuspended?: boolean
61
+ DynamicScalingOutSuspended?: boolean
62
+ ScheduledScalingSuspended?: boolean
63
+ }
64
+ }
65
+
66
+ export interface ScalingPolicy {
67
+ PolicyARN?: string
68
+ PolicyName: string
69
+ ServiceNamespace: ServiceNamespace
70
+ ResourceId: string
71
+ ScalableDimension: ScalableDimension
72
+ PolicyType: 'TargetTrackingScaling' | 'StepScaling'
73
+ StepScalingPolicyConfiguration?: StepScalingPolicyConfiguration
74
+ TargetTrackingScalingPolicyConfiguration?: TargetTrackingScalingPolicyConfiguration
75
+ Alarms?: Array<{
76
+ AlarmName: string
77
+ AlarmARN: string
78
+ }>
79
+ CreationTime?: string
80
+ }
81
+
82
+ export interface StepScalingPolicyConfiguration {
83
+ AdjustmentType: 'ChangeInCapacity' | 'PercentChangeInCapacity' | 'ExactCapacity'
84
+ StepAdjustments: Array<{
85
+ MetricIntervalLowerBound?: number
86
+ MetricIntervalUpperBound?: number
87
+ ScalingAdjustment: number
88
+ }>
89
+ MinAdjustmentMagnitude?: number
90
+ Cooldown?: number
91
+ MetricAggregationType?: 'Average' | 'Minimum' | 'Maximum'
92
+ }
93
+
94
+ export interface TargetTrackingScalingPolicyConfiguration {
95
+ TargetValue: number
96
+ PredefinedMetricSpecification?: {
97
+ PredefinedMetricType: MetricType
98
+ ResourceLabel?: string
99
+ }
100
+ CustomizedMetricSpecification?: {
101
+ MetricName: string
102
+ Namespace: string
103
+ Statistic: 'Average' | 'Minimum' | 'Maximum' | 'SampleCount' | 'Sum'
104
+ Unit?: string
105
+ Dimensions?: Array<{
106
+ Name: string
107
+ Value: string
108
+ }>
109
+ }
110
+ ScaleOutCooldown?: number
111
+ ScaleInCooldown?: number
112
+ DisableScaleIn?: boolean
113
+ }
114
+
115
+ export interface ScheduledAction {
116
+ ScheduledActionName: string
117
+ ScheduledActionARN?: string
118
+ ServiceNamespace: ServiceNamespace
119
+ Schedule: string
120
+ Timezone?: string
121
+ ResourceId: string
122
+ ScalableDimension: ScalableDimension
123
+ StartTime?: string
124
+ EndTime?: string
125
+ ScalableTargetAction?: {
126
+ MinCapacity?: number
127
+ MaxCapacity?: number
128
+ }
129
+ CreationTime?: string
130
+ }
131
+
132
+ /**
133
+ * Application Auto Scaling client for ECS, DynamoDB, and other services
134
+ */
135
+ export class ApplicationAutoScalingClient {
136
+ private client: AWSClient
137
+ private region: string
138
+
139
+ constructor(region: string = 'us-east-1') {
140
+ this.region = region
141
+ this.client = new AWSClient()
142
+ }
143
+
144
+ /**
145
+ * Register a scalable target
146
+ * This must be done before creating scaling policies
147
+ */
148
+ async registerScalableTarget(options: {
149
+ serviceNamespace: ServiceNamespace
150
+ resourceId: string
151
+ scalableDimension: ScalableDimension
152
+ minCapacity: number
153
+ maxCapacity: number
154
+ roleARN?: string
155
+ suspendedState?: {
156
+ dynamicScalingInSuspended?: boolean
157
+ dynamicScalingOutSuspended?: boolean
158
+ scheduledScalingSuspended?: boolean
159
+ }
160
+ }): Promise<void> {
161
+ const params: Record<string, any> = {
162
+ ServiceNamespace: options.serviceNamespace,
163
+ ResourceId: options.resourceId,
164
+ ScalableDimension: options.scalableDimension,
165
+ MinCapacity: options.minCapacity,
166
+ MaxCapacity: options.maxCapacity,
167
+ }
168
+
169
+ if (options.roleARN) {
170
+ params.RoleARN = options.roleARN
171
+ }
172
+
173
+ if (options.suspendedState) {
174
+ params.SuspendedState = {
175
+ DynamicScalingInSuspended: options.suspendedState.dynamicScalingInSuspended,
176
+ DynamicScalingOutSuspended: options.suspendedState.dynamicScalingOutSuspended,
177
+ ScheduledScalingSuspended: options.suspendedState.scheduledScalingSuspended,
178
+ }
179
+ }
180
+
181
+ await this.client.request({
182
+ service: 'application-autoscaling',
183
+ region: this.region,
184
+ method: 'POST',
185
+ path: '/',
186
+ headers: {
187
+ 'X-Amz-Target': 'AnyScaleFrontendService.RegisterScalableTarget',
188
+ 'Content-Type': 'application/x-amz-json-1.1',
189
+ },
190
+ body: JSON.stringify(params),
191
+ })
192
+ }
193
+
194
+ /**
195
+ * Describe scalable targets
196
+ */
197
+ async describeScalableTargets(options: {
198
+ serviceNamespace: ServiceNamespace
199
+ resourceIds?: string[]
200
+ scalableDimension?: ScalableDimension
201
+ maxResults?: number
202
+ nextToken?: string
203
+ }): Promise<{ ScalableTargets: ScalableTarget[], NextToken?: string }> {
204
+ const params: Record<string, any> = {
205
+ ServiceNamespace: options.serviceNamespace,
206
+ }
207
+
208
+ if (options.resourceIds && options.resourceIds.length > 0) {
209
+ params.ResourceIds = options.resourceIds
210
+ }
211
+
212
+ if (options.scalableDimension) {
213
+ params.ScalableDimension = options.scalableDimension
214
+ }
215
+
216
+ if (options.maxResults) {
217
+ params.MaxResults = options.maxResults
218
+ }
219
+
220
+ if (options.nextToken) {
221
+ params.NextToken = options.nextToken
222
+ }
223
+
224
+ const result = await this.client.request({
225
+ service: 'application-autoscaling',
226
+ region: this.region,
227
+ method: 'POST',
228
+ path: '/',
229
+ headers: {
230
+ 'X-Amz-Target': 'AnyScaleFrontendService.DescribeScalableTargets',
231
+ 'Content-Type': 'application/x-amz-json-1.1',
232
+ },
233
+ body: JSON.stringify(params),
234
+ })
235
+
236
+ return {
237
+ ScalableTargets: result.ScalableTargets || [],
238
+ NextToken: result.NextToken,
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Deregister a scalable target
244
+ */
245
+ async deregisterScalableTarget(options: {
246
+ serviceNamespace: ServiceNamespace
247
+ resourceId: string
248
+ scalableDimension: ScalableDimension
249
+ }): Promise<void> {
250
+ const params = {
251
+ ServiceNamespace: options.serviceNamespace,
252
+ ResourceId: options.resourceId,
253
+ ScalableDimension: options.scalableDimension,
254
+ }
255
+
256
+ await this.client.request({
257
+ service: 'application-autoscaling',
258
+ region: this.region,
259
+ method: 'POST',
260
+ path: '/',
261
+ headers: {
262
+ 'X-Amz-Target': 'AnyScaleFrontendService.DeregisterScalableTarget',
263
+ 'Content-Type': 'application/x-amz-json-1.1',
264
+ },
265
+ body: JSON.stringify(params),
266
+ })
267
+ }
268
+
269
+ /**
270
+ * Put a scaling policy (create or update)
271
+ */
272
+ async putScalingPolicy(options: {
273
+ policyName: string
274
+ serviceNamespace: ServiceNamespace
275
+ resourceId: string
276
+ scalableDimension: ScalableDimension
277
+ policyType: 'TargetTrackingScaling' | 'StepScaling'
278
+ targetTrackingScalingPolicyConfiguration?: TargetTrackingScalingPolicyConfiguration
279
+ stepScalingPolicyConfiguration?: StepScalingPolicyConfiguration
280
+ }): Promise<{ PolicyARN: string, Alarms: Array<{ AlarmName: string, AlarmARN: string }> }> {
281
+ const params: Record<string, any> = {
282
+ PolicyName: options.policyName,
283
+ ServiceNamespace: options.serviceNamespace,
284
+ ResourceId: options.resourceId,
285
+ ScalableDimension: options.scalableDimension,
286
+ PolicyType: options.policyType,
287
+ }
288
+
289
+ if (options.targetTrackingScalingPolicyConfiguration) {
290
+ params.TargetTrackingScalingPolicyConfiguration = options.targetTrackingScalingPolicyConfiguration
291
+ }
292
+
293
+ if (options.stepScalingPolicyConfiguration) {
294
+ params.StepScalingPolicyConfiguration = options.stepScalingPolicyConfiguration
295
+ }
296
+
297
+ const result = await this.client.request({
298
+ service: 'application-autoscaling',
299
+ region: this.region,
300
+ method: 'POST',
301
+ path: '/',
302
+ headers: {
303
+ 'X-Amz-Target': 'AnyScaleFrontendService.PutScalingPolicy',
304
+ 'Content-Type': 'application/x-amz-json-1.1',
305
+ },
306
+ body: JSON.stringify(params),
307
+ })
308
+
309
+ return {
310
+ PolicyARN: result.PolicyARN || '',
311
+ Alarms: result.Alarms || [],
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Describe scaling policies
317
+ */
318
+ async describeScalingPolicies(options: {
319
+ serviceNamespace: ServiceNamespace
320
+ policyNames?: string[]
321
+ resourceId?: string
322
+ scalableDimension?: ScalableDimension
323
+ maxResults?: number
324
+ nextToken?: string
325
+ }): Promise<{ ScalingPolicies: ScalingPolicy[], NextToken?: string }> {
326
+ const params: Record<string, any> = {
327
+ ServiceNamespace: options.serviceNamespace,
328
+ }
329
+
330
+ if (options.policyNames && options.policyNames.length > 0) {
331
+ params.PolicyNames = options.policyNames
332
+ }
333
+
334
+ if (options.resourceId) {
335
+ params.ResourceId = options.resourceId
336
+ }
337
+
338
+ if (options.scalableDimension) {
339
+ params.ScalableDimension = options.scalableDimension
340
+ }
341
+
342
+ if (options.maxResults) {
343
+ params.MaxResults = options.maxResults
344
+ }
345
+
346
+ if (options.nextToken) {
347
+ params.NextToken = options.nextToken
348
+ }
349
+
350
+ const result = await this.client.request({
351
+ service: 'application-autoscaling',
352
+ region: this.region,
353
+ method: 'POST',
354
+ path: '/',
355
+ headers: {
356
+ 'X-Amz-Target': 'AnyScaleFrontendService.DescribeScalingPolicies',
357
+ 'Content-Type': 'application/x-amz-json-1.1',
358
+ },
359
+ body: JSON.stringify(params),
360
+ })
361
+
362
+ return {
363
+ ScalingPolicies: result.ScalingPolicies || [],
364
+ NextToken: result.NextToken,
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Delete a scaling policy
370
+ */
371
+ async deleteScalingPolicy(options: {
372
+ policyName: string
373
+ serviceNamespace: ServiceNamespace
374
+ resourceId: string
375
+ scalableDimension: ScalableDimension
376
+ }): Promise<void> {
377
+ const params = {
378
+ PolicyName: options.policyName,
379
+ ServiceNamespace: options.serviceNamespace,
380
+ ResourceId: options.resourceId,
381
+ ScalableDimension: options.scalableDimension,
382
+ }
383
+
384
+ await this.client.request({
385
+ service: 'application-autoscaling',
386
+ region: this.region,
387
+ method: 'POST',
388
+ path: '/',
389
+ headers: {
390
+ 'X-Amz-Target': 'AnyScaleFrontendService.DeleteScalingPolicy',
391
+ 'Content-Type': 'application/x-amz-json-1.1',
392
+ },
393
+ body: JSON.stringify(params),
394
+ })
395
+ }
396
+
397
+ /**
398
+ * Put a scheduled action
399
+ */
400
+ async putScheduledAction(options: {
401
+ scheduledActionName: string
402
+ serviceNamespace: ServiceNamespace
403
+ resourceId: string
404
+ scalableDimension: ScalableDimension
405
+ schedule: string
406
+ timezone?: string
407
+ startTime?: Date
408
+ endTime?: Date
409
+ scalableTargetAction?: {
410
+ minCapacity?: number
411
+ maxCapacity?: number
412
+ }
413
+ }): Promise<void> {
414
+ const params: Record<string, any> = {
415
+ ScheduledActionName: options.scheduledActionName,
416
+ ServiceNamespace: options.serviceNamespace,
417
+ ResourceId: options.resourceId,
418
+ ScalableDimension: options.scalableDimension,
419
+ Schedule: options.schedule,
420
+ }
421
+
422
+ if (options.timezone) {
423
+ params.Timezone = options.timezone
424
+ }
425
+
426
+ if (options.startTime) {
427
+ params.StartTime = options.startTime.toISOString()
428
+ }
429
+
430
+ if (options.endTime) {
431
+ params.EndTime = options.endTime.toISOString()
432
+ }
433
+
434
+ if (options.scalableTargetAction) {
435
+ params.ScalableTargetAction = options.scalableTargetAction
436
+ }
437
+
438
+ await this.client.request({
439
+ service: 'application-autoscaling',
440
+ region: this.region,
441
+ method: 'POST',
442
+ path: '/',
443
+ headers: {
444
+ 'X-Amz-Target': 'AnyScaleFrontendService.PutScheduledAction',
445
+ 'Content-Type': 'application/x-amz-json-1.1',
446
+ },
447
+ body: JSON.stringify(params),
448
+ })
449
+ }
450
+
451
+ /**
452
+ * Describe scheduled actions
453
+ */
454
+ async describeScheduledActions(options: {
455
+ serviceNamespace: ServiceNamespace
456
+ scheduledActionNames?: string[]
457
+ resourceId?: string
458
+ scalableDimension?: ScalableDimension
459
+ maxResults?: number
460
+ nextToken?: string
461
+ }): Promise<{ ScheduledActions: ScheduledAction[], NextToken?: string }> {
462
+ const params: Record<string, any> = {
463
+ ServiceNamespace: options.serviceNamespace,
464
+ }
465
+
466
+ if (options.scheduledActionNames && options.scheduledActionNames.length > 0) {
467
+ params.ScheduledActionNames = options.scheduledActionNames
468
+ }
469
+
470
+ if (options.resourceId) {
471
+ params.ResourceId = options.resourceId
472
+ }
473
+
474
+ if (options.scalableDimension) {
475
+ params.ScalableDimension = options.scalableDimension
476
+ }
477
+
478
+ if (options.maxResults) {
479
+ params.MaxResults = options.maxResults
480
+ }
481
+
482
+ if (options.nextToken) {
483
+ params.NextToken = options.nextToken
484
+ }
485
+
486
+ const result = await this.client.request({
487
+ service: 'application-autoscaling',
488
+ region: this.region,
489
+ method: 'POST',
490
+ path: '/',
491
+ headers: {
492
+ 'X-Amz-Target': 'AnyScaleFrontendService.DescribeScheduledActions',
493
+ 'Content-Type': 'application/x-amz-json-1.1',
494
+ },
495
+ body: JSON.stringify(params),
496
+ })
497
+
498
+ return {
499
+ ScheduledActions: result.ScheduledActions || [],
500
+ NextToken: result.NextToken,
501
+ }
502
+ }
503
+
504
+ /**
505
+ * Delete a scheduled action
506
+ */
507
+ async deleteScheduledAction(options: {
508
+ scheduledActionName: string
509
+ serviceNamespace: ServiceNamespace
510
+ resourceId: string
511
+ scalableDimension: ScalableDimension
512
+ }): Promise<void> {
513
+ const params = {
514
+ ScheduledActionName: options.scheduledActionName,
515
+ ServiceNamespace: options.serviceNamespace,
516
+ ResourceId: options.resourceId,
517
+ ScalableDimension: options.scalableDimension,
518
+ }
519
+
520
+ await this.client.request({
521
+ service: 'application-autoscaling',
522
+ region: this.region,
523
+ method: 'POST',
524
+ path: '/',
525
+ headers: {
526
+ 'X-Amz-Target': 'AnyScaleFrontendService.DeleteScheduledAction',
527
+ 'Content-Type': 'application/x-amz-json-1.1',
528
+ },
529
+ body: JSON.stringify(params),
530
+ })
531
+ }
532
+
533
+ /**
534
+ * Describe scaling activities
535
+ */
536
+ async describeScalingActivities(options: {
537
+ serviceNamespace: ServiceNamespace
538
+ resourceId?: string
539
+ scalableDimension?: ScalableDimension
540
+ maxResults?: number
541
+ nextToken?: string
542
+ includeNotScaledActivities?: boolean
543
+ }): Promise<{
544
+ ScalingActivities: Array<{
545
+ ActivityId: string
546
+ ServiceNamespace: string
547
+ ResourceId: string
548
+ ScalableDimension: string
549
+ Description: string
550
+ Cause: string
551
+ StartTime: string
552
+ EndTime?: string
553
+ StatusCode: 'Pending' | 'InProgress' | 'Successful' | 'Overridden' | 'Unfulfilled' | 'Failed'
554
+ StatusMessage?: string
555
+ Details?: string
556
+ NotScaledReasons?: Array<{
557
+ Code: string
558
+ MaxCapacity?: number
559
+ MinCapacity?: number
560
+ CurrentCapacity?: number
561
+ }>
562
+ }>
563
+ NextToken?: string
564
+ }> {
565
+ const params: Record<string, any> = {
566
+ ServiceNamespace: options.serviceNamespace,
567
+ }
568
+
569
+ if (options.resourceId) {
570
+ params.ResourceId = options.resourceId
571
+ }
572
+
573
+ if (options.scalableDimension) {
574
+ params.ScalableDimension = options.scalableDimension
575
+ }
576
+
577
+ if (options.maxResults) {
578
+ params.MaxResults = options.maxResults
579
+ }
580
+
581
+ if (options.nextToken) {
582
+ params.NextToken = options.nextToken
583
+ }
584
+
585
+ if (options.includeNotScaledActivities !== undefined) {
586
+ params.IncludeNotScaledActivities = options.includeNotScaledActivities
587
+ }
588
+
589
+ const result = await this.client.request({
590
+ service: 'application-autoscaling',
591
+ region: this.region,
592
+ method: 'POST',
593
+ path: '/',
594
+ headers: {
595
+ 'X-Amz-Target': 'AnyScaleFrontendService.DescribeScalingActivities',
596
+ 'Content-Type': 'application/x-amz-json-1.1',
597
+ },
598
+ body: JSON.stringify(params),
599
+ })
600
+
601
+ return {
602
+ ScalingActivities: result.ScalingActivities || [],
603
+ NextToken: result.NextToken,
604
+ }
605
+ }
606
+
607
+ // ============================================
608
+ // ECS-Specific Helper Methods
609
+ // ============================================
610
+
611
+ /**
612
+ * Helper: Get the resource ID format for an ECS service
613
+ */
614
+ getECSServiceResourceId(clusterName: string, serviceName: string): string {
615
+ return `service/${clusterName}/${serviceName}`
616
+ }
617
+
618
+ /**
619
+ * Helper: Register an ECS service for auto-scaling
620
+ */
621
+ async registerECSServiceScaling(options: {
622
+ clusterName: string
623
+ serviceName: string
624
+ minCapacity: number
625
+ maxCapacity: number
626
+ }): Promise<void> {
627
+ const resourceId = this.getECSServiceResourceId(options.clusterName, options.serviceName)
628
+
629
+ await this.registerScalableTarget({
630
+ serviceNamespace: 'ecs',
631
+ resourceId,
632
+ scalableDimension: 'ecs:service:DesiredCount',
633
+ minCapacity: options.minCapacity,
634
+ maxCapacity: options.maxCapacity,
635
+ })
636
+ }
637
+
638
+ /**
639
+ * Helper: Create a CPU-based scaling policy for an ECS service
640
+ */
641
+ async createECSCPUScalingPolicy(options: {
642
+ clusterName: string
643
+ serviceName: string
644
+ policyName: string
645
+ targetCPUPercent: number
646
+ scaleOutCooldown?: number
647
+ scaleInCooldown?: number
648
+ disableScaleIn?: boolean
649
+ }): Promise<{ PolicyARN: string, Alarms: Array<{ AlarmName: string, AlarmARN: string }> }> {
650
+ const resourceId = this.getECSServiceResourceId(options.clusterName, options.serviceName)
651
+
652
+ return this.putScalingPolicy({
653
+ policyName: options.policyName,
654
+ serviceNamespace: 'ecs',
655
+ resourceId,
656
+ scalableDimension: 'ecs:service:DesiredCount',
657
+ policyType: 'TargetTrackingScaling',
658
+ targetTrackingScalingPolicyConfiguration: {
659
+ TargetValue: options.targetCPUPercent,
660
+ PredefinedMetricSpecification: {
661
+ PredefinedMetricType: 'ECSServiceAverageCPUUtilization',
662
+ },
663
+ ScaleOutCooldown: options.scaleOutCooldown ?? 300,
664
+ ScaleInCooldown: options.scaleInCooldown ?? 300,
665
+ DisableScaleIn: options.disableScaleIn ?? false,
666
+ },
667
+ })
668
+ }
669
+
670
+ /**
671
+ * Helper: Create a memory-based scaling policy for an ECS service
672
+ */
673
+ async createECSMemoryScalingPolicy(options: {
674
+ clusterName: string
675
+ serviceName: string
676
+ policyName: string
677
+ targetMemoryPercent: number
678
+ scaleOutCooldown?: number
679
+ scaleInCooldown?: number
680
+ disableScaleIn?: boolean
681
+ }): Promise<{ PolicyARN: string, Alarms: Array<{ AlarmName: string, AlarmARN: string }> }> {
682
+ const resourceId = this.getECSServiceResourceId(options.clusterName, options.serviceName)
683
+
684
+ return this.putScalingPolicy({
685
+ policyName: options.policyName,
686
+ serviceNamespace: 'ecs',
687
+ resourceId,
688
+ scalableDimension: 'ecs:service:DesiredCount',
689
+ policyType: 'TargetTrackingScaling',
690
+ targetTrackingScalingPolicyConfiguration: {
691
+ TargetValue: options.targetMemoryPercent,
692
+ PredefinedMetricSpecification: {
693
+ PredefinedMetricType: 'ECSServiceAverageMemoryUtilization',
694
+ },
695
+ ScaleOutCooldown: options.scaleOutCooldown ?? 300,
696
+ ScaleInCooldown: options.scaleInCooldown ?? 300,
697
+ DisableScaleIn: options.disableScaleIn ?? false,
698
+ },
699
+ })
700
+ }
701
+
702
+ /**
703
+ * Helper: Create an ALB request count scaling policy for an ECS service
704
+ */
705
+ async createECSRequestCountScalingPolicy(options: {
706
+ clusterName: string
707
+ serviceName: string
708
+ policyName: string
709
+ targetRequestsPerTarget: number
710
+ targetGroupArn: string
711
+ loadBalancerArn: string
712
+ scaleOutCooldown?: number
713
+ scaleInCooldown?: number
714
+ disableScaleIn?: boolean
715
+ }): Promise<{ PolicyARN: string, Alarms: Array<{ AlarmName: string, AlarmARN: string }> }> {
716
+ const resourceId = this.getECSServiceResourceId(options.clusterName, options.serviceName)
717
+
718
+ // Extract the suffix from ARN for resource label
719
+ // Format: app/load-balancer-name/xxx/targetgroup/target-group-name/yyy
720
+ const tgArnParts = options.targetGroupArn.split(':').pop() || ''
721
+ const lbArnParts = options.loadBalancerArn.split(':').pop() || ''
722
+ const tgSuffix = tgArnParts.replace('targetgroup/', '')
723
+ const lbSuffix = lbArnParts.replace('loadbalancer/', '')
724
+ const resourceLabel = `${lbSuffix}/${tgSuffix}`
725
+
726
+ return this.putScalingPolicy({
727
+ policyName: options.policyName,
728
+ serviceNamespace: 'ecs',
729
+ resourceId,
730
+ scalableDimension: 'ecs:service:DesiredCount',
731
+ policyType: 'TargetTrackingScaling',
732
+ targetTrackingScalingPolicyConfiguration: {
733
+ TargetValue: options.targetRequestsPerTarget,
734
+ PredefinedMetricSpecification: {
735
+ PredefinedMetricType: 'ALBRequestCountPerTarget',
736
+ ResourceLabel: resourceLabel,
737
+ },
738
+ ScaleOutCooldown: options.scaleOutCooldown ?? 300,
739
+ ScaleInCooldown: options.scaleInCooldown ?? 300,
740
+ DisableScaleIn: options.disableScaleIn ?? false,
741
+ },
742
+ })
743
+ }
744
+
745
+ /**
746
+ * Helper: Get all scaling policies for an ECS service
747
+ */
748
+ async getECSServiceScalingPolicies(clusterName: string, serviceName: string): Promise<ScalingPolicy[]> {
749
+ const resourceId = this.getECSServiceResourceId(clusterName, serviceName)
750
+
751
+ const result = await this.describeScalingPolicies({
752
+ serviceNamespace: 'ecs',
753
+ resourceId,
754
+ scalableDimension: 'ecs:service:DesiredCount',
755
+ })
756
+
757
+ return result.ScalingPolicies
758
+ }
759
+
760
+ /**
761
+ * Helper: Remove all auto-scaling from an ECS service
762
+ */
763
+ async removeECSServiceScaling(clusterName: string, serviceName: string): Promise<void> {
764
+ const resourceId = this.getECSServiceResourceId(clusterName, serviceName)
765
+
766
+ // First, delete all scaling policies
767
+ const policies = await this.getECSServiceScalingPolicies(clusterName, serviceName)
768
+ for (const policy of policies) {
769
+ await this.deleteScalingPolicy({
770
+ policyName: policy.PolicyName,
771
+ serviceNamespace: 'ecs',
772
+ resourceId,
773
+ scalableDimension: 'ecs:service:DesiredCount',
774
+ })
775
+ }
776
+
777
+ // Then deregister the scalable target
778
+ await this.deregisterScalableTarget({
779
+ serviceNamespace: 'ecs',
780
+ resourceId,
781
+ scalableDimension: 'ecs:service:DesiredCount',
782
+ })
783
+ }
784
+
785
+ /**
786
+ * Helper: Create a scheduled scaling action for an ECS service
787
+ * Example schedule: "cron(0 9 * * ? *)" for 9 AM daily
788
+ */
789
+ async createECSScheduledScaling(options: {
790
+ clusterName: string
791
+ serviceName: string
792
+ actionName: string
793
+ schedule: string
794
+ timezone?: string
795
+ minCapacity?: number
796
+ maxCapacity?: number
797
+ }): Promise<void> {
798
+ const resourceId = this.getECSServiceResourceId(options.clusterName, options.serviceName)
799
+
800
+ await this.putScheduledAction({
801
+ scheduledActionName: options.actionName,
802
+ serviceNamespace: 'ecs',
803
+ resourceId,
804
+ scalableDimension: 'ecs:service:DesiredCount',
805
+ schedule: options.schedule,
806
+ timezone: options.timezone,
807
+ scalableTargetAction: {
808
+ minCapacity: options.minCapacity,
809
+ maxCapacity: options.maxCapacity,
810
+ },
811
+ })
812
+ }
813
+
814
+ /**
815
+ * Helper: Get scaling activity history for an ECS service
816
+ */
817
+ async getECSScalingActivities(clusterName: string, serviceName: string, maxResults = 20): Promise<Array<{
818
+ ActivityId: string
819
+ Description: string
820
+ Cause: string
821
+ StartTime: string
822
+ EndTime?: string
823
+ StatusCode: string
824
+ StatusMessage?: string
825
+ }>> {
826
+ const resourceId = this.getECSServiceResourceId(clusterName, serviceName)
827
+
828
+ const result = await this.describeScalingActivities({
829
+ serviceNamespace: 'ecs',
830
+ resourceId,
831
+ scalableDimension: 'ecs:service:DesiredCount',
832
+ maxResults,
833
+ })
834
+
835
+ return result.ScalingActivities.map(activity => ({
836
+ ActivityId: activity.ActivityId,
837
+ Description: activity.Description,
838
+ Cause: activity.Cause,
839
+ StartTime: activity.StartTime,
840
+ EndTime: activity.EndTime,
841
+ StatusCode: activity.StatusCode,
842
+ StatusMessage: activity.StatusMessage,
843
+ }))
844
+ }
845
+ }