Skip to content

fix(lambda): fix user agent and headers for remote debugging#8304

Merged
laileni-aws merged 14 commits intoaws:masterfrom
valerena:fix-lambda-debugging
Nov 19, 2025
Merged

fix(lambda): fix user agent and headers for remote debugging#8304
laileni-aws merged 14 commits intoaws:masterfrom
valerena:fix-lambda-debugging

Conversation

@valerena
Copy link
Contributor

Problem

The AWS SDK v2 to v3 migration in PR #8183 introduced breaking changes for LocalStack compatibility and Lambda debugging is not working anymore:

  1. User Agent format changed: The migration changed from string-based user agents to AWS SDK v3's UserAgent pairs format ([name, version] tuples), but several places still used the old string format, breaking LocalStack's custom user agent for Lambda debugging and part of the integration with IoT
  2. Response headers no longer accessible: AWS SDK v3 removed access to HTTP response headers via $response.httpResponse.headers, breaking LocalStack connection detection which relies on the x-localstack-request-url header

These issues were not caught most likely because LocalStack compatibility was not tested during the SDK v3 migration.

Solution

  1. Fix user agent format for AWS SDK v3

    • Migrated from string-based user agents to proper UserAgent pairs format:

      • Changed from "LAMBDA-DEBUG/1.0.0 AWS-Toolkit/..." (string)
      • To [['LAMBDA-DEBUG', '1.0.0'], ['AWS-Toolkit', '2.0'], ...] (pairs)
    • Updated awsClientBuilderV3 to use customUserAgent instead of userAgent

  2. Add response headers middleware for AWS SDK v3

    • Added captureHeadersMiddleware to AWSClientBuilderV3 that attaches HTTP response headers to the output via $httpHeaders property
    • Updated loginManager to check for LocalStack connection using $httpHeaders instead of the removed $response.httpResponse.headers

AWS SDK v3 Breaking Changes

User Agent Format

SDK v2:

// String format in client options
const options = {
    region: 'us-east-1',
    userAgent: 'LAMBDA-DEBUG/1.0.0 AWS-Toolkit/2.0.0'
}

SDK v3:

// Array of [name, version] tuples
const options = {
    region: 'us-east-1',
    customUserAgent: [
        ['LAMBDA-DEBUG', '1.0.0'],
        ['AWS-Toolkit', '2.0.0']
    ]
}

Response Headers Access

SDK v2:

const response = await client.send(command)
// Headers directly accessible
const headers = response.$response.httpResponse.headers
const localStackUrl = headers['x-localstack-request-url']

SDK v3:

const response = await client.send(command)
// Headers NOT accessible by default - requires custom middleware
const headers = response.$httpHeaders  // undefined without middleware

Supersedes #8289 and #8291


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@valerena valerena requested a review from a team as a code owner November 17, 2025 22:49
@valerena valerena force-pushed the fix-lambda-debugging branch from 3139d19 to da91360 Compare November 18, 2025 02:40
@valerena valerena changed the title fix(lambda/localstack): fix user agent and headers for remote debugging fix(lambda): fix user agent and headers for remote debugging Nov 18, 2025
There's a `Visual-Studio-Code---Insiders/` that didn't fit previous test that
was checking for `Visual-Studio-Code/` (slash included).

Rename some of the errors to make it clearer if there's one failing too.
@valerena valerena closed this Nov 18, 2025
@valerena valerena reopened this Nov 18, 2025
@amazon-inspector-ohio
Copy link

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@amazon-inspector-ohio
Copy link

✅ I finished the code review, and didn't find any security or code quality issues.

@laileni-aws laileni-aws enabled auto-merge (squash) November 18, 2025 23:59
@laileni-aws laileni-aws merged commit a450753 into aws:master Nov 19, 2025
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants