Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(appbuilder): SAM local debugging: region and credential in launch config should override toolkit default #6011

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/shared/sam/debugger/awsSamDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
}

const runtimeFamily = getFamily(runtime)
const region = this.ctx.awsContext.getCredentialDefaultRegion()
// use region in debug config first, if not found, fall back to toolkit default region.
const region = config.aws?.region ?? this.ctx.awsContext.getCredentialDefaultRegion()
const documentUri =
vscode.window.activeTextEditor?.document.uri ??
// XXX: don't know what URI to choose...
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/shared/sam/localLambdaRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ToolkitError, UnknownError } from '../errors'
import { SamCliError } from './cli/samCliInvokerUtils'
import fs from '../fs/fs'
import { getSpawnEnv } from '../env/resolveEnv'
import { asEnvironmentVariables } from '../../auth/credentials/utils'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -287,10 +288,17 @@ export async function runLambdaFunction(
getLogger().info(localize('AWS.output.sam.local.startRun', 'Preparing to run locally: {0}', config.handlerName))
}

const envVars = await getSpawnEnv({
...process.env,
...(config.aws?.region ? { AWS_DEFAULT_REGION: config.aws.region } : {}),
})
const envVars = await getSpawnEnv(
{
...process.env,
...(config.awsCredentials ? asEnvironmentVariables(config.awsCredentials) : {}),
...(config.aws?.region ? { AWS_DEFAULT_REGION: config.aws.region } : {}),
},
{
// only inject toolkit credential if config credential is not set
injectCredential: config.awsCredentials ? false : true,
}
)

const settings = SamCliSettings.instance
const timer = new Timeout(settings.getLocalInvokeTimeout())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,7 @@ describe('SamDebugConfigurationProvider', async function () {
const tempDir = path.dirname(actual.codeRoot)

const expected: SamLaunchRequestArgs = {
// The `aws.credentials` field in debug config, overrides default toolkit credentials.
awsCredentials: configCredentials,
...awsSection,
type: AWS_SAM_DEBUG_TYPE,
Expand Down Expand Up @@ -2949,7 +2950,8 @@ describe('SamDebugConfigurationProvider', async function () {
templatePath: pathutil.normalize(path.join(actual.baseBuildDir!, 'app___vsctk___template.yaml')),
parameterOverrides: undefined,
architecture: 'x86_64',
region: 'us-west-2',
// The `aws.region` field in debug config, overrides default toolkit region.
region: 'us-weast-9',

//
// Node-related fields
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "SAM local debugging: `aws.region` and `aws.credentials` specified in launch config should override default Toolkit region and credentials"
}
Loading