@@ -4,6 +4,7 @@ import * as os from "node:os";
44import * as path from "node:path" ;
55
66import { window } from "vscode" ;
7+ import type { LogOutputChannel } from "vscode" ;
78
89import { parseIni , serializeIni , updateIniSection } from "./ini-parser.ts" ;
910import type { IniFile , IniSection } from "./ini-parser.ts" ;
@@ -98,11 +99,16 @@ async function getProfile(filename: string, profileName: string) {
9899 return { contents, iniFile, section } ;
99100}
100101
101- async function dnsResolveCheck ( ) : Promise < boolean > {
102+ async function dnsResolveCheck (
103+ outputChannel : LogOutputChannel | undefined ,
104+ ) : Promise < boolean > {
102105 try {
103106 const addresses = await resolve ( "test.localhost.localstack.cloud" ) ;
104107 return addresses . includes ( "127.0.0.1" ) ;
105108 } catch ( error ) {
109+ outputChannel ?. debug (
110+ `[aws-profile]: Could not resolve "test.localhost.localstack.cloud". Falling back to "http://127.0.0.1:4566" for the endpoint_url in AWS profile "localstack". Your system may have DNS Rebind Protection enabled, which can block custom DNS names like "localhost.localstack.cloud"` ,
111+ ) ;
106112 return false ;
107113 }
108114}
@@ -115,6 +121,7 @@ async function configureAwsConfigProfile(
115121 iniFile : IniFile ,
116122 section : IniSection | undefined ,
117123 overrideDecision : OverrideDecision | undefined = undefined ,
124+ outputChannel : LogOutputChannel | undefined ,
118125) : Promise < boolean | undefined > {
119126 const awsConfigFilenameReadable = awsConfigFilename . replace (
120127 os . homedir ( ) ,
@@ -128,7 +135,7 @@ async function configureAwsConfigProfile(
128135 // User chose to override the existing profile.
129136
130137 // check if dnsResolveCheck is successful
131- const isDnsResolved = await dnsResolveCheck ( ) ;
138+ const isDnsResolved = await dnsResolveCheck ( outputChannel ) ;
132139 const endpointUrl = isDnsResolved
133140 ? `http://localhost.localstack.cloud:${ DEFAULT_PORT } `
134141 : `http://127.0.0.1:${ DEFAULT_PORT } ` ;
@@ -155,7 +162,7 @@ async function configureAwsConfigProfile(
155162
156163 // LocalStack profile does not exist: create it.
157164 // check if dnsResolveCheck is successful
158- const isDnsResolved = await dnsResolveCheck ( ) ;
165+ const isDnsResolved = await dnsResolveCheck ( outputChannel ) ;
159166 const endpointUrl = isDnsResolved
160167 ? `http://localhost.localstack.cloud:${ DEFAULT_PORT } `
161168 : `http://127.0.0.1:${ DEFAULT_PORT } ` ;
@@ -276,6 +283,7 @@ export async function configureAwsProfiles(options: {
276283 forceOverride ?: boolean ; // for testing purposes
277284 notifyNoChangesMade ?: boolean ;
278285 origin ?: "manual_trigger" | "extension_startup" ;
286+ outputChannel ?: LogOutputChannel ;
279287} ) {
280288 const trigger = options . origin ?? "manual_trigger" ;
281289 const startedAt = new Date ( ) . toISOString ( ) ;
@@ -373,6 +381,7 @@ export async function configureAwsProfiles(options: {
373381 configIniFile ,
374382 configSection ,
375383 overrideDecision ,
384+ options . outputChannel ,
376385 ) ,
377386 configureCredentialsProfile (
378387 awsCredentialsFilename ,
@@ -403,6 +412,7 @@ export async function configureAwsProfiles(options: {
403412 configIniFile ,
404413 configSection ,
405414 overrideDecision ,
415+ options . outputChannel ,
406416 ) ;
407417 window . showInformationMessage (
408418 'Successfully added the AWS profile named "localstack" to "~/.aws/config".' ,
0 commit comments