@stacksjs/ts-cloud 0.1.2 → 0.1.5

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 (187) hide show
  1. package/README.md +98 -13
  2. package/dist/aws/acm.d.ts +129 -0
  3. package/dist/aws/application-autoscaling.d.ts +282 -0
  4. package/dist/aws/bedrock.d.ts +2292 -0
  5. package/dist/aws/client.d.ts +79 -0
  6. package/dist/aws/cloudformation.d.ts +105 -0
  7. package/dist/aws/cloudfront.d.ts +265 -0
  8. package/dist/aws/cloudwatch-logs.d.ts +48 -0
  9. package/dist/aws/comprehend.d.ts +505 -0
  10. package/dist/aws/connect.d.ts +377 -0
  11. package/dist/aws/deploy-imap.d.ts +14 -0
  12. package/dist/aws/dynamodb.d.ts +176 -0
  13. package/dist/aws/ec2.d.ts +272 -0
  14. package/dist/aws/ecr.d.ts +149 -0
  15. package/dist/aws/ecs.d.ts +162 -0
  16. package/dist/aws/elasticache.d.ts +71 -0
  17. package/dist/aws/elbv2.d.ts +248 -0
  18. package/dist/aws/email.d.ts +175 -0
  19. package/dist/aws/eventbridge.d.ts +142 -0
  20. package/dist/aws/iam.d.ts +638 -0
  21. package/dist/aws/imap-server.d.ts +119 -0
  22. package/{src/aws/index.ts → dist/aws/index.d.ts} +62 -83
  23. package/{src/aws/kendra.ts → dist/aws/kendra.d.ts} +71 -386
  24. package/dist/aws/lambda.d.ts +232 -0
  25. package/dist/aws/opensearch.d.ts +87 -0
  26. package/dist/aws/personalize.d.ts +516 -0
  27. package/dist/aws/polly.d.ts +214 -0
  28. package/dist/aws/rds.d.ts +240 -0
  29. package/dist/aws/rekognition.d.ts +543 -0
  30. package/dist/aws/route53-domains.d.ts +113 -0
  31. package/dist/aws/route53.d.ts +215 -0
  32. package/dist/aws/s3.d.ts +212 -0
  33. package/dist/aws/scheduler.d.ts +140 -0
  34. package/dist/aws/secrets-manager.d.ts +170 -0
  35. package/dist/aws/ses.d.ts +288 -0
  36. package/dist/aws/setup-phone.d.ts +0 -0
  37. package/dist/aws/setup-sms.d.ts +115 -0
  38. package/dist/aws/sms.d.ts +304 -0
  39. package/dist/aws/smtp-server.d.ts +61 -0
  40. package/dist/aws/sns.d.ts +117 -0
  41. package/dist/aws/sqs.d.ts +65 -0
  42. package/dist/aws/ssm.d.ts +179 -0
  43. package/dist/aws/sts.d.ts +15 -0
  44. package/dist/aws/support.d.ts +104 -0
  45. package/dist/aws/test-imap.d.ts +0 -0
  46. package/dist/aws/textract.d.ts +403 -0
  47. package/dist/aws/transcribe.d.ts +60 -0
  48. package/dist/aws/translate.d.ts +358 -0
  49. package/dist/aws/voice.d.ts +219 -0
  50. package/dist/bin/cli.js +1724 -0
  51. package/dist/config.d.ts +7 -0
  52. package/dist/deploy/index.d.ts +2 -0
  53. package/dist/deploy/static-site-external-dns.d.ts +51 -0
  54. package/dist/deploy/static-site.d.ts +71 -0
  55. package/dist/dns/cloudflare.d.ts +52 -0
  56. package/dist/dns/godaddy.d.ts +38 -0
  57. package/dist/dns/index.d.ts +45 -0
  58. package/dist/dns/porkbun.d.ts +18 -0
  59. package/dist/dns/route53-adapter.d.ts +38 -0
  60. package/{src/dns/types.ts → dist/dns/types.d.ts} +26 -63
  61. package/dist/dns/validator.d.ts +78 -0
  62. package/dist/generators/index.d.ts +1 -0
  63. package/dist/generators/infrastructure.d.ts +30 -0
  64. package/{src/index.ts → dist/index.d.ts} +70 -93
  65. package/dist/index.js +7881 -0
  66. package/dist/push/apns.d.ts +60 -0
  67. package/dist/push/fcm.d.ts +117 -0
  68. package/dist/push/index.d.ts +14 -0
  69. package/dist/security/pre-deploy-scanner.d.ts +69 -0
  70. package/dist/ssl/acme-client.d.ts +67 -0
  71. package/dist/ssl/index.d.ts +2 -0
  72. package/dist/ssl/letsencrypt.d.ts +48 -0
  73. package/dist/types.d.ts +1 -0
  74. package/dist/utils/cli.d.ts +123 -0
  75. package/dist/validation/index.d.ts +1 -0
  76. package/dist/validation/template.d.ts +23 -0
  77. package/package.json +8 -8
  78. package/bin/cli.ts +0 -133
  79. package/bin/commands/analytics.ts +0 -328
  80. package/bin/commands/api.ts +0 -379
  81. package/bin/commands/assets.ts +0 -221
  82. package/bin/commands/audit.ts +0 -501
  83. package/bin/commands/backup.ts +0 -682
  84. package/bin/commands/cache.ts +0 -294
  85. package/bin/commands/cdn.ts +0 -281
  86. package/bin/commands/config.ts +0 -202
  87. package/bin/commands/container.ts +0 -105
  88. package/bin/commands/cost.ts +0 -208
  89. package/bin/commands/database.ts +0 -401
  90. package/bin/commands/deploy.ts +0 -674
  91. package/bin/commands/domain.ts +0 -397
  92. package/bin/commands/email.ts +0 -423
  93. package/bin/commands/environment.ts +0 -285
  94. package/bin/commands/events.ts +0 -424
  95. package/bin/commands/firewall.ts +0 -145
  96. package/bin/commands/function.ts +0 -116
  97. package/bin/commands/generate.ts +0 -280
  98. package/bin/commands/git.ts +0 -139
  99. package/bin/commands/iam.ts +0 -464
  100. package/bin/commands/index.ts +0 -48
  101. package/bin/commands/init.ts +0 -120
  102. package/bin/commands/logs.ts +0 -148
  103. package/bin/commands/network.ts +0 -579
  104. package/bin/commands/notify.ts +0 -489
  105. package/bin/commands/queue.ts +0 -407
  106. package/bin/commands/scheduler.ts +0 -370
  107. package/bin/commands/secrets.ts +0 -54
  108. package/bin/commands/server.ts +0 -629
  109. package/bin/commands/shared.ts +0 -97
  110. package/bin/commands/ssl.ts +0 -138
  111. package/bin/commands/stack.ts +0 -325
  112. package/bin/commands/status.ts +0 -385
  113. package/bin/commands/storage.ts +0 -450
  114. package/bin/commands/team.ts +0 -96
  115. package/bin/commands/tunnel.ts +0 -489
  116. package/bin/commands/utils.ts +0 -202
  117. package/build.ts +0 -15
  118. package/cloud +0 -2
  119. package/src/aws/acm.ts +0 -768
  120. package/src/aws/application-autoscaling.ts +0 -845
  121. package/src/aws/bedrock.ts +0 -4074
  122. package/src/aws/client.ts +0 -878
  123. package/src/aws/cloudformation.ts +0 -896
  124. package/src/aws/cloudfront.ts +0 -1531
  125. package/src/aws/cloudwatch-logs.ts +0 -154
  126. package/src/aws/comprehend.ts +0 -839
  127. package/src/aws/connect.ts +0 -1056
  128. package/src/aws/deploy-imap.ts +0 -384
  129. package/src/aws/dynamodb.ts +0 -340
  130. package/src/aws/ec2.ts +0 -1385
  131. package/src/aws/ecr.ts +0 -621
  132. package/src/aws/ecs.ts +0 -615
  133. package/src/aws/elasticache.ts +0 -301
  134. package/src/aws/elbv2.ts +0 -942
  135. package/src/aws/email.ts +0 -928
  136. package/src/aws/eventbridge.ts +0 -248
  137. package/src/aws/iam.ts +0 -1689
  138. package/src/aws/imap-server.ts +0 -2100
  139. package/src/aws/lambda.ts +0 -786
  140. package/src/aws/opensearch.ts +0 -158
  141. package/src/aws/personalize.ts +0 -977
  142. package/src/aws/polly.ts +0 -559
  143. package/src/aws/rds.ts +0 -888
  144. package/src/aws/rekognition.ts +0 -846
  145. package/src/aws/route53-domains.ts +0 -359
  146. package/src/aws/route53.ts +0 -1046
  147. package/src/aws/s3.ts +0 -2318
  148. package/src/aws/scheduler.ts +0 -571
  149. package/src/aws/secrets-manager.ts +0 -769
  150. package/src/aws/ses.ts +0 -1081
  151. package/src/aws/setup-phone.ts +0 -104
  152. package/src/aws/setup-sms.ts +0 -580
  153. package/src/aws/sms.ts +0 -1735
  154. package/src/aws/smtp-server.ts +0 -531
  155. package/src/aws/sns.ts +0 -758
  156. package/src/aws/sqs.ts +0 -382
  157. package/src/aws/ssm.ts +0 -807
  158. package/src/aws/sts.ts +0 -92
  159. package/src/aws/support.ts +0 -391
  160. package/src/aws/test-imap.ts +0 -86
  161. package/src/aws/textract.ts +0 -780
  162. package/src/aws/transcribe.ts +0 -108
  163. package/src/aws/translate.ts +0 -641
  164. package/src/aws/voice.ts +0 -1379
  165. package/src/config.ts +0 -35
  166. package/src/deploy/index.ts +0 -7
  167. package/src/deploy/static-site-external-dns.ts +0 -906
  168. package/src/deploy/static-site.ts +0 -1125
  169. package/src/dns/godaddy.ts +0 -412
  170. package/src/dns/index.ts +0 -183
  171. package/src/dns/porkbun.ts +0 -362
  172. package/src/dns/route53-adapter.ts +0 -414
  173. package/src/dns/validator.ts +0 -369
  174. package/src/generators/index.ts +0 -5
  175. package/src/generators/infrastructure.ts +0 -1660
  176. package/src/push/apns.ts +0 -452
  177. package/src/push/fcm.ts +0 -506
  178. package/src/push/index.ts +0 -58
  179. package/src/ssl/acme-client.ts +0 -478
  180. package/src/ssl/index.ts +0 -7
  181. package/src/ssl/letsencrypt.ts +0 -747
  182. package/src/types.ts +0 -2
  183. package/src/utils/cli.ts +0 -398
  184. package/src/validation/index.ts +0 -5
  185. package/src/validation/template.ts +0 -405
  186. package/test/index.test.ts +0 -128
  187. package/tsconfig.json +0 -18
@@ -1,845 +0,0 @@
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
- }