@@ -141,10 +141,21 @@ try {
141141
142142 // Get AWS account ID for ECR
143143 const accountId = process . env . AWS_ACCOUNT_ID || await getAwsAccountId ( region )
144+
145+ // Validate account ID before proceeding
146+ if ( ! accountId || accountId . length < 10 ) {
147+ throw new Error (
148+ `Invalid AWS Account ID: "${ accountId || '(empty)' } "\n` +
149+ `Set AWS_ACCOUNT_ID in your .env file or ensure valid AWS credentials are configured.`
150+ )
151+ }
152+
144153 const projectName = cloudConfigModule ?. tsCloud ?. project ?. name || 'stacks'
145154 const ecrRepository = `${ accountId } .dkr.ecr.${ region } .amazonaws.com/${ projectName } -${ environment } -api`
146155 const imageTag = `${ ecrRepository } :latest`
147156
157+ if ( isVerbose ) log . debug ( `ECR repository: ${ ecrRepository } ` )
158+
148159 // Step 1: Verify ECR credentials (actual login happens before push)
149160 if ( isVerbose ) log . debug ( 'ECR credentials will be validated before push...' )
150161
@@ -281,8 +292,11 @@ try {
281292 const { STSClient } = await import ( 'ts-cloud/aws' )
282293 const sts = new STSClient ( region )
283294 const identity = await sts . getCallerIdentity ( )
284- return identity . Account || process . env . AWS_ACCOUNT_ID || ''
285- } catch ( error ) {
295+ const accountId = identity . Account || process . env . AWS_ACCOUNT_ID || ''
296+ if ( isVerbose ) log . debug ( `Retrieved AWS Account ID: ${ accountId || '(empty)' } ` )
297+ return accountId
298+ } catch ( error : any ) {
299+ if ( isVerbose ) log . debug ( `Failed to get AWS Account ID: ${ error . message } ` )
286300 // Fallback to environment variable
287301 return process . env . AWS_ACCOUNT_ID || ''
288302 }
0 commit comments