@stacksjs/ts-cloud 0.1.3 → 0.1.6
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.
- package/README.md +98 -13
- package/dist/aws/acm.d.ts +129 -0
- package/dist/aws/application-autoscaling.d.ts +282 -0
- package/dist/aws/bedrock.d.ts +2292 -0
- package/dist/aws/client.d.ts +79 -0
- package/dist/aws/cloudformation.d.ts +105 -0
- package/dist/aws/cloudfront.d.ts +265 -0
- package/dist/aws/cloudwatch-logs.d.ts +48 -0
- package/dist/aws/comprehend.d.ts +505 -0
- package/dist/aws/connect.d.ts +377 -0
- package/dist/aws/deploy-imap.d.ts +14 -0
- package/dist/aws/dynamodb.d.ts +176 -0
- package/dist/aws/ec2.d.ts +272 -0
- package/dist/aws/ecr.d.ts +149 -0
- package/dist/aws/ecs.d.ts +162 -0
- package/dist/aws/elasticache.d.ts +71 -0
- package/dist/aws/elbv2.d.ts +248 -0
- package/dist/aws/email.d.ts +175 -0
- package/dist/aws/eventbridge.d.ts +142 -0
- package/dist/aws/iam.d.ts +638 -0
- package/dist/aws/imap-server.d.ts +119 -0
- package/{src/aws/index.ts → dist/aws/index.d.ts} +62 -83
- package/{src/aws/kendra.ts → dist/aws/kendra.d.ts} +71 -386
- package/dist/aws/lambda.d.ts +232 -0
- package/dist/aws/opensearch.d.ts +87 -0
- package/dist/aws/personalize.d.ts +516 -0
- package/dist/aws/polly.d.ts +214 -0
- package/dist/aws/rds.d.ts +240 -0
- package/dist/aws/rekognition.d.ts +543 -0
- package/dist/aws/route53-domains.d.ts +113 -0
- package/dist/aws/route53.d.ts +215 -0
- package/dist/aws/s3.d.ts +212 -0
- package/dist/aws/scheduler.d.ts +140 -0
- package/dist/aws/secrets-manager.d.ts +170 -0
- package/dist/aws/ses.d.ts +288 -0
- package/dist/aws/setup-phone.d.ts +0 -0
- package/dist/aws/setup-sms.d.ts +115 -0
- package/dist/aws/sms.d.ts +304 -0
- package/dist/aws/smtp-server.d.ts +61 -0
- package/dist/aws/sns.d.ts +117 -0
- package/dist/aws/sqs.d.ts +65 -0
- package/dist/aws/ssm.d.ts +179 -0
- package/dist/aws/sts.d.ts +15 -0
- package/dist/aws/support.d.ts +104 -0
- package/dist/aws/test-imap.d.ts +0 -0
- package/dist/aws/textract.d.ts +403 -0
- package/dist/aws/transcribe.d.ts +60 -0
- package/dist/aws/translate.d.ts +358 -0
- package/dist/aws/voice.d.ts +219 -0
- package/dist/bin/cli.js +1724 -0
- package/dist/config.d.ts +7 -0
- package/dist/deploy/index.d.ts +2 -0
- package/dist/deploy/static-site-external-dns.d.ts +51 -0
- package/dist/deploy/static-site.d.ts +71 -0
- package/dist/dns/cloudflare.d.ts +52 -0
- package/dist/dns/godaddy.d.ts +38 -0
- package/dist/dns/index.d.ts +45 -0
- package/dist/dns/porkbun.d.ts +18 -0
- package/dist/dns/route53-adapter.d.ts +38 -0
- package/{src/dns/types.ts → dist/dns/types.d.ts} +26 -63
- package/dist/dns/validator.d.ts +78 -0
- package/dist/generators/index.d.ts +1 -0
- package/dist/generators/infrastructure.d.ts +30 -0
- package/{src/index.ts → dist/index.d.ts} +70 -93
- package/dist/index.js +7881 -0
- package/dist/push/apns.d.ts +60 -0
- package/dist/push/fcm.d.ts +117 -0
- package/dist/push/index.d.ts +14 -0
- package/dist/security/pre-deploy-scanner.d.ts +69 -0
- package/dist/ssl/acme-client.d.ts +67 -0
- package/dist/ssl/index.d.ts +2 -0
- package/dist/ssl/letsencrypt.d.ts +48 -0
- package/dist/types.d.ts +1 -0
- package/dist/utils/cli.d.ts +123 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/template.d.ts +23 -0
- package/package.json +8 -8
- package/bin/cli.ts +0 -133
- package/bin/commands/analytics.ts +0 -328
- package/bin/commands/api.ts +0 -379
- package/bin/commands/assets.ts +0 -221
- package/bin/commands/audit.ts +0 -501
- package/bin/commands/backup.ts +0 -682
- package/bin/commands/cache.ts +0 -294
- package/bin/commands/cdn.ts +0 -281
- package/bin/commands/config.ts +0 -202
- package/bin/commands/container.ts +0 -105
- package/bin/commands/cost.ts +0 -208
- package/bin/commands/database.ts +0 -401
- package/bin/commands/deploy.ts +0 -674
- package/bin/commands/domain.ts +0 -397
- package/bin/commands/email.ts +0 -423
- package/bin/commands/environment.ts +0 -285
- package/bin/commands/events.ts +0 -424
- package/bin/commands/firewall.ts +0 -145
- package/bin/commands/function.ts +0 -116
- package/bin/commands/generate.ts +0 -280
- package/bin/commands/git.ts +0 -139
- package/bin/commands/iam.ts +0 -464
- package/bin/commands/index.ts +0 -48
- package/bin/commands/init.ts +0 -120
- package/bin/commands/logs.ts +0 -148
- package/bin/commands/network.ts +0 -579
- package/bin/commands/notify.ts +0 -489
- package/bin/commands/queue.ts +0 -407
- package/bin/commands/scheduler.ts +0 -370
- package/bin/commands/secrets.ts +0 -54
- package/bin/commands/server.ts +0 -629
- package/bin/commands/shared.ts +0 -97
- package/bin/commands/ssl.ts +0 -138
- package/bin/commands/stack.ts +0 -325
- package/bin/commands/status.ts +0 -385
- package/bin/commands/storage.ts +0 -450
- package/bin/commands/team.ts +0 -96
- package/bin/commands/tunnel.ts +0 -489
- package/bin/commands/utils.ts +0 -202
- package/build.ts +0 -15
- package/cloud +0 -2
- package/src/aws/acm.ts +0 -768
- package/src/aws/application-autoscaling.ts +0 -845
- package/src/aws/bedrock.ts +0 -4074
- package/src/aws/client.ts +0 -878
- package/src/aws/cloudformation.ts +0 -896
- package/src/aws/cloudfront.ts +0 -1531
- package/src/aws/cloudwatch-logs.ts +0 -154
- package/src/aws/comprehend.ts +0 -839
- package/src/aws/connect.ts +0 -1056
- package/src/aws/deploy-imap.ts +0 -384
- package/src/aws/dynamodb.ts +0 -340
- package/src/aws/ec2.ts +0 -1385
- package/src/aws/ecr.ts +0 -621
- package/src/aws/ecs.ts +0 -615
- package/src/aws/elasticache.ts +0 -301
- package/src/aws/elbv2.ts +0 -942
- package/src/aws/email.ts +0 -928
- package/src/aws/eventbridge.ts +0 -248
- package/src/aws/iam.ts +0 -1689
- package/src/aws/imap-server.ts +0 -2100
- package/src/aws/lambda.ts +0 -786
- package/src/aws/opensearch.ts +0 -158
- package/src/aws/personalize.ts +0 -977
- package/src/aws/polly.ts +0 -559
- package/src/aws/rds.ts +0 -888
- package/src/aws/rekognition.ts +0 -846
- package/src/aws/route53-domains.ts +0 -359
- package/src/aws/route53.ts +0 -1046
- package/src/aws/s3.ts +0 -2318
- package/src/aws/scheduler.ts +0 -571
- package/src/aws/secrets-manager.ts +0 -769
- package/src/aws/ses.ts +0 -1081
- package/src/aws/setup-phone.ts +0 -104
- package/src/aws/setup-sms.ts +0 -580
- package/src/aws/sms.ts +0 -1735
- package/src/aws/smtp-server.ts +0 -531
- package/src/aws/sns.ts +0 -758
- package/src/aws/sqs.ts +0 -382
- package/src/aws/ssm.ts +0 -807
- package/src/aws/sts.ts +0 -92
- package/src/aws/support.ts +0 -391
- package/src/aws/test-imap.ts +0 -86
- package/src/aws/textract.ts +0 -780
- package/src/aws/transcribe.ts +0 -108
- package/src/aws/translate.ts +0 -641
- package/src/aws/voice.ts +0 -1379
- package/src/config.ts +0 -35
- package/src/deploy/index.ts +0 -7
- package/src/deploy/static-site-external-dns.ts +0 -906
- package/src/deploy/static-site.ts +0 -1125
- package/src/dns/godaddy.ts +0 -412
- package/src/dns/index.ts +0 -183
- package/src/dns/porkbun.ts +0 -362
- package/src/dns/route53-adapter.ts +0 -414
- package/src/dns/validator.ts +0 -369
- package/src/generators/index.ts +0 -5
- package/src/generators/infrastructure.ts +0 -1660
- package/src/push/apns.ts +0 -452
- package/src/push/fcm.ts +0 -506
- package/src/push/index.ts +0 -58
- package/src/ssl/acme-client.ts +0 -478
- package/src/ssl/index.ts +0 -7
- package/src/ssl/letsencrypt.ts +0 -747
- package/src/types.ts +0 -2
- package/src/utils/cli.ts +0 -398
- package/src/validation/index.ts +0 -5
- package/src/validation/template.ts +0 -405
- package/test/index.test.ts +0 -128
- package/tsconfig.json +0 -18
package/bin/commands/shared.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import type { CloudConfig } from '@stacksjs/ts-cloud-types'
|
|
3
|
-
import { loadCloudConfig } from '../../src/config'
|
|
4
|
-
import { createDnsProvider, DnsProviderFactory } from '../../src/dns'
|
|
5
|
-
import type { DnsProviderConfig, DnsProvider } from '../../src/dns/types'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Load and validate the cloud config, ensuring project config exists.
|
|
9
|
-
* Returns the config with project guaranteed to exist.
|
|
10
|
-
*/
|
|
11
|
-
export async function loadValidatedConfig(): Promise<CloudConfig> {
|
|
12
|
-
const cloudConfig = await loadCloudConfig()
|
|
13
|
-
if (!cloudConfig.project) {
|
|
14
|
-
throw new Error('Missing required project configuration in cloud.config.ts')
|
|
15
|
-
}
|
|
16
|
-
return cloudConfig as CloudConfig
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Resolve DNS provider configuration from CLI options and environment variables
|
|
21
|
-
*/
|
|
22
|
-
export function resolveDnsProviderConfig(providerName?: string): DnsProviderConfig | null {
|
|
23
|
-
// Explicit provider from CLI option
|
|
24
|
-
if (providerName) {
|
|
25
|
-
switch (providerName.toLowerCase()) {
|
|
26
|
-
case 'porkbun': {
|
|
27
|
-
const apiKey = process.env.PORKBUN_API_KEY
|
|
28
|
-
const secretKey = process.env.PORKBUN_SECRET_KEY
|
|
29
|
-
if (!apiKey || !secretKey) {
|
|
30
|
-
throw new Error('PORKBUN_API_KEY and PORKBUN_SECRET_KEY environment variables are required for Porkbun provider')
|
|
31
|
-
}
|
|
32
|
-
return { provider: 'porkbun', apiKey, secretKey }
|
|
33
|
-
}
|
|
34
|
-
case 'godaddy': {
|
|
35
|
-
const apiKey = process.env.GODADDY_API_KEY
|
|
36
|
-
const apiSecret = process.env.GODADDY_API_SECRET
|
|
37
|
-
if (!apiKey || !apiSecret) {
|
|
38
|
-
throw new Error('GODADDY_API_KEY and GODADDY_API_SECRET environment variables are required for GoDaddy provider')
|
|
39
|
-
}
|
|
40
|
-
const environment = (process.env.GODADDY_ENVIRONMENT as 'production' | 'ote') || 'production'
|
|
41
|
-
return { provider: 'godaddy', apiKey, apiSecret, environment }
|
|
42
|
-
}
|
|
43
|
-
case 'route53': {
|
|
44
|
-
const region = process.env.AWS_REGION || 'us-east-1'
|
|
45
|
-
const hostedZoneId = process.env.AWS_HOSTED_ZONE_ID
|
|
46
|
-
return { provider: 'route53', region, hostedZoneId }
|
|
47
|
-
}
|
|
48
|
-
default:
|
|
49
|
-
throw new Error(`Unknown DNS provider: ${providerName}. Supported: porkbun, godaddy, route53`)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Auto-detect from environment
|
|
54
|
-
const factory = new DnsProviderFactory().loadFromEnv()
|
|
55
|
-
const providers = factory.getAllProviders()
|
|
56
|
-
|
|
57
|
-
if (providers.length === 0) {
|
|
58
|
-
return null
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Return the first configured provider's config
|
|
62
|
-
if (process.env.PORKBUN_API_KEY && process.env.PORKBUN_SECRET_KEY) {
|
|
63
|
-
return {
|
|
64
|
-
provider: 'porkbun',
|
|
65
|
-
apiKey: process.env.PORKBUN_API_KEY,
|
|
66
|
-
secretKey: process.env.PORKBUN_SECRET_KEY,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (process.env.GODADDY_API_KEY && process.env.GODADDY_API_SECRET) {
|
|
70
|
-
return {
|
|
71
|
-
provider: 'godaddy',
|
|
72
|
-
apiKey: process.env.GODADDY_API_KEY,
|
|
73
|
-
apiSecret: process.env.GODADDY_API_SECRET,
|
|
74
|
-
environment: (process.env.GODADDY_ENVIRONMENT as 'production' | 'ote') || 'production',
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (process.env.AWS_ACCESS_KEY_ID || process.env.AWS_REGION) {
|
|
78
|
-
return {
|
|
79
|
-
provider: 'route53',
|
|
80
|
-
region: process.env.AWS_REGION || 'us-east-1',
|
|
81
|
-
hostedZoneId: process.env.AWS_HOSTED_ZONE_ID,
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Get a DNS provider instance from configuration
|
|
90
|
-
*/
|
|
91
|
-
export function getDnsProvider(providerName?: string): DnsProvider {
|
|
92
|
-
const config = resolveDnsProviderConfig(providerName)
|
|
93
|
-
if (!config) {
|
|
94
|
-
throw new Error('No DNS provider configured. Set environment variables for Porkbun (PORKBUN_API_KEY, PORKBUN_SECRET_KEY), GoDaddy (GODADDY_API_KEY, GODADDY_API_SECRET), or Route53 (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)')
|
|
95
|
-
}
|
|
96
|
-
return createDnsProvider(config)
|
|
97
|
-
}
|
package/bin/commands/ssl.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { CLI } from '@stacksjs/clapp'
|
|
2
|
-
import * as cli from '../../src/utils/cli'
|
|
3
|
-
import { ACMClient } from '../../src/aws/acm'
|
|
4
|
-
|
|
5
|
-
export function registerSslCommands(app: CLI): void {
|
|
6
|
-
app
|
|
7
|
-
.command('ssl:list', 'List all SSL certificates')
|
|
8
|
-
.option('--region <region>', 'AWS region (default: us-east-1)')
|
|
9
|
-
.action(async (options?: { region?: string }) => {
|
|
10
|
-
cli.header('SSL Certificates')
|
|
11
|
-
|
|
12
|
-
const region = options?.region || 'us-east-1'
|
|
13
|
-
const spinner = new cli.Spinner('Fetching certificates from ACM...')
|
|
14
|
-
spinner.start()
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const acm = new ACMClient(region)
|
|
18
|
-
|
|
19
|
-
// List all certificates
|
|
20
|
-
const result = await acm.listCertificates()
|
|
21
|
-
|
|
22
|
-
if (result.CertificateSummaryList.length === 0) {
|
|
23
|
-
spinner.succeed('No certificates found')
|
|
24
|
-
cli.info(`\nNo SSL certificates found in region ${region}`)
|
|
25
|
-
cli.info('Use \'cloud domain:ssl <domain>\' to request a new certificate')
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Get details for each certificate
|
|
30
|
-
const certDetails = await Promise.all(
|
|
31
|
-
result.CertificateSummaryList.map(async (cert) => {
|
|
32
|
-
const details = await acm.describeCertificate({ CertificateArn: cert.CertificateArn })
|
|
33
|
-
return details
|
|
34
|
-
}),
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
spinner.succeed(`Found ${certDetails.length} certificate(s)`)
|
|
38
|
-
|
|
39
|
-
// Helper to format AWS timestamp (seconds since epoch)
|
|
40
|
-
const formatDate = (timestamp: string | number | undefined): string => {
|
|
41
|
-
if (!timestamp) return 'N/A'
|
|
42
|
-
// AWS returns seconds since epoch, JS Date expects milliseconds
|
|
43
|
-
const ts = typeof timestamp === 'string' ? Number.parseFloat(timestamp) : timestamp
|
|
44
|
-
const ms = ts < 1e12 ? ts * 1000 : ts // Convert if seconds
|
|
45
|
-
return new Date(ms).toISOString().split('T')[0]
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Format the table data
|
|
49
|
-
const tableData = certDetails.map((cert) => {
|
|
50
|
-
const expiry = formatDate(cert.NotAfter)
|
|
51
|
-
const typeDisplay = cert.Type === 'AMAZON_ISSUED' ? 'Amazon Issued' : cert.Type || 'Unknown'
|
|
52
|
-
const inUse = cert.Status === 'ISSUED' ? 'Available' : cert.Status || 'Unknown'
|
|
53
|
-
|
|
54
|
-
return [
|
|
55
|
-
cert.DomainName,
|
|
56
|
-
cert.Status || 'Unknown',
|
|
57
|
-
expiry,
|
|
58
|
-
typeDisplay,
|
|
59
|
-
inUse,
|
|
60
|
-
]
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
cli.table(
|
|
64
|
-
['Domain', 'Status', 'Expiry', 'Type', 'State'],
|
|
65
|
-
tableData,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
cli.info('\nACM certificates are automatically renewed by AWS')
|
|
69
|
-
cli.info(`Region: ${region}`)
|
|
70
|
-
}
|
|
71
|
-
catch (error: any) {
|
|
72
|
-
spinner.fail('Failed to fetch certificates')
|
|
73
|
-
cli.error(error.message)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
app
|
|
78
|
-
.command('ssl:renew <domain>', 'Renew SSL certificate')
|
|
79
|
-
.option('--region <region>', 'AWS region (default: us-east-1)')
|
|
80
|
-
.action(async (domain: string, options?: { region?: string }) => {
|
|
81
|
-
cli.header(`Checking SSL Certificate for ${domain}`)
|
|
82
|
-
|
|
83
|
-
const region = options?.region || 'us-east-1'
|
|
84
|
-
cli.info(`Domain: ${domain}`)
|
|
85
|
-
cli.info(`Region: ${region}`)
|
|
86
|
-
|
|
87
|
-
const spinner = new cli.Spinner('Checking certificate status...')
|
|
88
|
-
spinner.start()
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const acm = new ACMClient(region)
|
|
92
|
-
|
|
93
|
-
// Find certificate by domain
|
|
94
|
-
const cert = await acm.findCertificateByDomain(domain)
|
|
95
|
-
|
|
96
|
-
if (!cert) {
|
|
97
|
-
spinner.fail('Certificate not found')
|
|
98
|
-
cli.error(`No certificate found for domain: ${domain}`)
|
|
99
|
-
cli.info('Use \'cloud domain:ssl <domain>\' to request a new certificate')
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
spinner.succeed('Certificate found')
|
|
104
|
-
|
|
105
|
-
cli.info('\nCertificate is managed by AWS Certificate Manager')
|
|
106
|
-
cli.info('ACM certificates are automatically renewed 60 days before expiry')
|
|
107
|
-
cli.warn('\nNo manual renewal needed for ACM certificates')
|
|
108
|
-
|
|
109
|
-
// Helper to format AWS timestamp (seconds since epoch)
|
|
110
|
-
const formatDate = (timestamp: string | number | undefined): string => {
|
|
111
|
-
if (!timestamp) return 'N/A'
|
|
112
|
-
const ts = typeof timestamp === 'string' ? Number.parseFloat(timestamp) : timestamp
|
|
113
|
-
const ms = ts < 1e12 ? ts * 1000 : ts
|
|
114
|
-
return new Date(ms).toISOString().split('T')[0]
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const expiry = formatDate(cert.NotAfter)
|
|
118
|
-
const issued = formatDate(cert.IssuedAt)
|
|
119
|
-
|
|
120
|
-
cli.info('\nCertificate details:')
|
|
121
|
-
cli.info(` - Domain: ${cert.DomainName}`)
|
|
122
|
-
cli.info(` - Status: ${cert.Status}`)
|
|
123
|
-
cli.info(` - Issued: ${issued}`)
|
|
124
|
-
cli.info(` - Expiry: ${expiry}`)
|
|
125
|
-
cli.info(` - Type: ${cert.Type || 'Unknown'}`)
|
|
126
|
-
cli.info(` - ARN: ${cert.CertificateArn}`)
|
|
127
|
-
cli.info(` - Auto-renewal: ${cert.Type === 'AMAZON_ISSUED' ? 'Enabled' : 'N/A (imported)'}`)
|
|
128
|
-
|
|
129
|
-
if (cert.SubjectAlternativeNames && cert.SubjectAlternativeNames.length > 1) {
|
|
130
|
-
cli.info(` - SANs: ${cert.SubjectAlternativeNames.join(', ')}`)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (error: any) {
|
|
134
|
-
spinner.fail('Failed to check certificate')
|
|
135
|
-
cli.error(error.message)
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
}
|
package/bin/commands/stack.ts
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import type { CLI } from '@stacksjs/clapp'
|
|
2
|
-
import { writeFileSync, statSync } from 'node:fs'
|
|
3
|
-
import * as cli from '../../src/utils/cli'
|
|
4
|
-
import { CloudFormationClient } from '../../src/aws/cloudformation'
|
|
5
|
-
import { loadValidatedConfig } from './shared'
|
|
6
|
-
|
|
7
|
-
export function registerStackCommands(app: CLI): void {
|
|
8
|
-
app
|
|
9
|
-
.command('stack:list', 'List all CloudFormation stacks')
|
|
10
|
-
.action(async () => {
|
|
11
|
-
cli.header('CloudFormation Stacks')
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const config = await loadValidatedConfig()
|
|
15
|
-
const region = config.project.region || 'us-east-1'
|
|
16
|
-
|
|
17
|
-
const cfn = new CloudFormationClient(region)
|
|
18
|
-
|
|
19
|
-
const spinner = new cli.Spinner('Loading stacks...')
|
|
20
|
-
spinner.start()
|
|
21
|
-
|
|
22
|
-
const result = await cfn.listStacks([
|
|
23
|
-
'CREATE_COMPLETE',
|
|
24
|
-
'UPDATE_COMPLETE',
|
|
25
|
-
'ROLLBACK_COMPLETE',
|
|
26
|
-
'UPDATE_ROLLBACK_COMPLETE',
|
|
27
|
-
'CREATE_IN_PROGRESS',
|
|
28
|
-
'UPDATE_IN_PROGRESS',
|
|
29
|
-
])
|
|
30
|
-
|
|
31
|
-
spinner.succeed(`Found ${result.StackSummaries.length} stacks`)
|
|
32
|
-
|
|
33
|
-
if (result.StackSummaries.length === 0) {
|
|
34
|
-
cli.info('No stacks found')
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Display stacks in a table
|
|
39
|
-
const headers = ['Stack Name', 'Status', 'Created', 'Updated']
|
|
40
|
-
const rows = result.StackSummaries.map(stack => [
|
|
41
|
-
stack.StackName,
|
|
42
|
-
stack.StackStatus,
|
|
43
|
-
new Date(stack.CreationTime).toLocaleString(),
|
|
44
|
-
stack.LastUpdatedTime ? new Date(stack.LastUpdatedTime).toLocaleString() : 'Never',
|
|
45
|
-
])
|
|
46
|
-
|
|
47
|
-
cli.table(headers, rows)
|
|
48
|
-
}
|
|
49
|
-
catch (error: any) {
|
|
50
|
-
cli.error(`Failed to list stacks: ${error.message}`)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
app
|
|
55
|
-
.command('stack:describe STACK_NAME', 'Describe a CloudFormation stack')
|
|
56
|
-
.action(async (stackName: string) => {
|
|
57
|
-
cli.header(`Stack: ${stackName}`)
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const config = await loadValidatedConfig()
|
|
61
|
-
const region = config.project.region || 'us-east-1'
|
|
62
|
-
|
|
63
|
-
const cfn = new CloudFormationClient(region)
|
|
64
|
-
|
|
65
|
-
const spinner = new cli.Spinner('Loading stack details...')
|
|
66
|
-
spinner.start()
|
|
67
|
-
|
|
68
|
-
const result = await cfn.describeStacks({ stackName })
|
|
69
|
-
|
|
70
|
-
if (!result.Stacks || result.Stacks.length === 0) {
|
|
71
|
-
spinner.fail('Stack not found')
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const stack = result.Stacks[0]
|
|
76
|
-
spinner.succeed('Stack details loaded')
|
|
77
|
-
|
|
78
|
-
// Display stack info
|
|
79
|
-
cli.info(`\nStack Information:`)
|
|
80
|
-
cli.info(` - Name: ${stack.StackName}`)
|
|
81
|
-
cli.info(` - Status: ${stack.StackStatus}`)
|
|
82
|
-
cli.info(` - Created: ${new Date(stack.CreationTime).toLocaleString()}`)
|
|
83
|
-
if (stack.LastUpdatedTime) {
|
|
84
|
-
cli.info(` - Updated: ${new Date(stack.LastUpdatedTime).toLocaleString()}`)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Display parameters
|
|
88
|
-
if (stack.Parameters && stack.Parameters.length > 0) {
|
|
89
|
-
cli.info('\nParameters:')
|
|
90
|
-
for (const param of stack.Parameters) {
|
|
91
|
-
cli.info(` - ${param.ParameterKey}: ${param.ParameterValue}`)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Display outputs
|
|
96
|
-
if (stack.Outputs && stack.Outputs.length > 0) {
|
|
97
|
-
cli.info('\nOutputs:')
|
|
98
|
-
for (const output of stack.Outputs) {
|
|
99
|
-
cli.info(` - ${output.OutputKey}: ${output.OutputValue}`)
|
|
100
|
-
if (output.Description) {
|
|
101
|
-
cli.info(` ${output.Description}`)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Display tags
|
|
107
|
-
if (stack.Tags && stack.Tags.length > 0) {
|
|
108
|
-
cli.info('\nTags:')
|
|
109
|
-
for (const tag of stack.Tags) {
|
|
110
|
-
cli.info(` - ${tag.Key}: ${tag.Value}`)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// List resources
|
|
115
|
-
cli.step('\nLoading stack resources...')
|
|
116
|
-
const resources = await cfn.listStackResources(stackName)
|
|
117
|
-
|
|
118
|
-
if (resources.StackResourceSummaries.length > 0) {
|
|
119
|
-
cli.info(`\nResources (${resources.StackResourceSummaries.length}):`)
|
|
120
|
-
const resourceHeaders = ['Logical ID', 'Type', 'Status']
|
|
121
|
-
const resourceRows = resources.StackResourceSummaries.slice(0, 10).map(resource => [
|
|
122
|
-
resource.LogicalResourceId,
|
|
123
|
-
resource.ResourceType,
|
|
124
|
-
resource.ResourceStatus,
|
|
125
|
-
])
|
|
126
|
-
|
|
127
|
-
cli.table(resourceHeaders, resourceRows)
|
|
128
|
-
|
|
129
|
-
if (resources.StackResourceSummaries.length > 10) {
|
|
130
|
-
cli.info(`\n... and ${resources.StackResourceSummaries.length - 10} more resources`)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (error: any) {
|
|
135
|
-
cli.error(`Failed to describe stack: ${error.message}`)
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
app
|
|
140
|
-
.command('stack:delete STACK_NAME', 'Delete a CloudFormation stack')
|
|
141
|
-
.action(async (stackName: string) => {
|
|
142
|
-
cli.header(`Delete Stack: ${stackName}`)
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const config = await loadValidatedConfig()
|
|
146
|
-
const region = config.project.region || 'us-east-1'
|
|
147
|
-
|
|
148
|
-
cli.warn('This will permanently delete the stack and all its resources!')
|
|
149
|
-
|
|
150
|
-
const confirmed = await cli.confirm('\nAre you sure you want to delete this stack?', false)
|
|
151
|
-
if (!confirmed) {
|
|
152
|
-
cli.info('Deletion cancelled')
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const cfn = new CloudFormationClient(region)
|
|
157
|
-
|
|
158
|
-
const spinner = new cli.Spinner('Deleting stack...')
|
|
159
|
-
spinner.start()
|
|
160
|
-
|
|
161
|
-
await cfn.deleteStack(stackName)
|
|
162
|
-
|
|
163
|
-
spinner.succeed('Stack deletion initiated')
|
|
164
|
-
|
|
165
|
-
// Wait for deletion
|
|
166
|
-
cli.step('Waiting for stack deletion...')
|
|
167
|
-
await cfn.waitForStack(stackName, 'stack-delete-complete')
|
|
168
|
-
|
|
169
|
-
cli.success('Stack deleted successfully!')
|
|
170
|
-
}
|
|
171
|
-
catch (error: any) {
|
|
172
|
-
cli.error(`Failed to delete stack: ${error.message}`)
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
app
|
|
177
|
-
.command('stack:events STACK_NAME', 'Show stack events')
|
|
178
|
-
.option('--limit <number>', 'Limit number of events', { default: '20' })
|
|
179
|
-
.action(async (stackName: string, options?: { limit?: string }) => {
|
|
180
|
-
cli.header(`Stack Events: ${stackName}`)
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const config = await loadValidatedConfig()
|
|
184
|
-
const region = config.project.region || 'us-east-1'
|
|
185
|
-
|
|
186
|
-
const cfn = new CloudFormationClient(region)
|
|
187
|
-
|
|
188
|
-
const spinner = new cli.Spinner('Loading events...')
|
|
189
|
-
spinner.start()
|
|
190
|
-
|
|
191
|
-
const result = await cfn.describeStackEvents(stackName)
|
|
192
|
-
|
|
193
|
-
spinner.succeed(`Found ${result.StackEvents.length} events`)
|
|
194
|
-
|
|
195
|
-
const limit = options?.limit ? Number.parseInt(options.limit) : 20
|
|
196
|
-
const events = result.StackEvents.slice(0, limit)
|
|
197
|
-
|
|
198
|
-
if (events.length === 0) {
|
|
199
|
-
cli.info('No events found')
|
|
200
|
-
return
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Display events
|
|
204
|
-
const headers = ['Time', 'Resource', 'Status', 'Reason']
|
|
205
|
-
const rows = events.map(event => [
|
|
206
|
-
new Date(event.Timestamp).toLocaleString(),
|
|
207
|
-
event.LogicalResourceId,
|
|
208
|
-
event.ResourceStatus,
|
|
209
|
-
event.ResourceStatusReason || '',
|
|
210
|
-
])
|
|
211
|
-
|
|
212
|
-
cli.table(headers, rows)
|
|
213
|
-
}
|
|
214
|
-
catch (error: any) {
|
|
215
|
-
cli.error(`Failed to load events: ${error.message}`)
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
app
|
|
220
|
-
.command('stack:outputs STACK_NAME', 'Show stack outputs')
|
|
221
|
-
.action(async (stackName: string) => {
|
|
222
|
-
cli.header(`Stack Outputs: ${stackName}`)
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
const config = await loadValidatedConfig()
|
|
226
|
-
const region = config.project.region || 'us-east-1'
|
|
227
|
-
|
|
228
|
-
const cfn = new CloudFormationClient(region)
|
|
229
|
-
|
|
230
|
-
const spinner = new cli.Spinner('Loading stack outputs...')
|
|
231
|
-
spinner.start()
|
|
232
|
-
|
|
233
|
-
const result = await cfn.describeStacks({ stackName })
|
|
234
|
-
|
|
235
|
-
if (!result.Stacks || result.Stacks.length === 0) {
|
|
236
|
-
spinner.fail('Stack not found')
|
|
237
|
-
return
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const stack = result.Stacks[0]
|
|
241
|
-
spinner.succeed('Stack outputs loaded')
|
|
242
|
-
|
|
243
|
-
if (!stack.Outputs || stack.Outputs.length === 0) {
|
|
244
|
-
cli.info('No outputs found for this stack')
|
|
245
|
-
return
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Display outputs in a table
|
|
249
|
-
const headers = ['Key', 'Value', 'Description', 'Export Name']
|
|
250
|
-
const rows = stack.Outputs.map(output => [
|
|
251
|
-
output.OutputKey || '',
|
|
252
|
-
output.OutputValue || '',
|
|
253
|
-
output.Description || '',
|
|
254
|
-
output.ExportName || '',
|
|
255
|
-
])
|
|
256
|
-
|
|
257
|
-
cli.table(headers, rows)
|
|
258
|
-
|
|
259
|
-
// Also display in key=value format for easy copying
|
|
260
|
-
cli.info('\nCopy-friendly format:')
|
|
261
|
-
for (const output of stack.Outputs) {
|
|
262
|
-
cli.info(`${output.OutputKey}=${output.OutputValue}`)
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
catch (error: any) {
|
|
266
|
-
cli.error(`Failed to load outputs: ${error.message}`)
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
app
|
|
271
|
-
.command('stack:export STACK_NAME', 'Export stack template')
|
|
272
|
-
.option('--output <file>', 'Output file path')
|
|
273
|
-
.option('--format <format>', 'Output format (json or yaml)', { default: 'json' })
|
|
274
|
-
.action(async (stackName: string, options?: { output?: string, format?: string }) => {
|
|
275
|
-
cli.header(`Export Stack: ${stackName}`)
|
|
276
|
-
|
|
277
|
-
try {
|
|
278
|
-
const config = await loadValidatedConfig()
|
|
279
|
-
const region = config.project.region || 'us-east-1'
|
|
280
|
-
|
|
281
|
-
const cfn = new CloudFormationClient(region)
|
|
282
|
-
|
|
283
|
-
const spinner = new cli.Spinner('Fetching stack template...')
|
|
284
|
-
spinner.start()
|
|
285
|
-
|
|
286
|
-
const result = await cfn.getTemplate(stackName)
|
|
287
|
-
|
|
288
|
-
if (!result.TemplateBody) {
|
|
289
|
-
spinner.fail('Template not found')
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
spinner.succeed('Template fetched')
|
|
294
|
-
|
|
295
|
-
const format = options?.format || 'json'
|
|
296
|
-
let templateContent = result.TemplateBody
|
|
297
|
-
|
|
298
|
-
// Parse and re-format if needed
|
|
299
|
-
if (format === 'json') {
|
|
300
|
-
const template = JSON.parse(templateContent)
|
|
301
|
-
templateContent = JSON.stringify(template, null, 2)
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Save to file or display
|
|
305
|
-
if (options?.output) {
|
|
306
|
-
const outputPath = options.output
|
|
307
|
-
writeFileSync(outputPath, templateContent, 'utf-8')
|
|
308
|
-
cli.success(`Template exported to: ${outputPath}`)
|
|
309
|
-
|
|
310
|
-
// Show file size
|
|
311
|
-
const stats = statSync(outputPath)
|
|
312
|
-
const sizeInKB = (stats.size / 1024).toFixed(2)
|
|
313
|
-
cli.info(`File size: ${sizeInKB} KB`)
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
// Display template
|
|
317
|
-
cli.info('\nTemplate:')
|
|
318
|
-
console.log(templateContent)
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (error: any) {
|
|
322
|
-
cli.error(`Failed to export template: ${error.message}`)
|
|
323
|
-
}
|
|
324
|
-
})
|
|
325
|
-
}
|