|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import * as vscode from 'vscode' |
| 7 | +import globals from '../../shared/extensionGlobals' |
| 8 | +import type { Lambda } from 'aws-sdk' |
| 9 | +import { getLogger } from '../../shared/logger/logger' |
| 10 | + |
| 11 | +const logger = getLogger() |
| 12 | + |
| 13 | +export const remoteDebugSnapshotString = 'aws.lambda.remoteDebugSnapshot' |
| 14 | + |
| 15 | +export interface DebugConfig { |
| 16 | + functionArn: string |
| 17 | + functionName: string |
| 18 | + port: number | undefined |
| 19 | + localRoot: string |
| 20 | + remoteRoot: string |
| 21 | + skipFiles: string[] |
| 22 | + shouldPublishVersion: boolean |
| 23 | + lambdaRuntime?: string // Lambda runtime (e.g., nodejs18.x) |
| 24 | + debuggerRuntime?: string // VS Code debugger runtime (e.g., node) |
| 25 | + outFiles?: string[] |
| 26 | + sourceMap?: boolean |
| 27 | + justMyCode?: boolean |
| 28 | + projectName?: string |
| 29 | + otherDebugParams?: string |
| 30 | + lambdaTimeout?: number |
| 31 | + layerArn?: string |
| 32 | + handlerFile?: string |
| 33 | + isLambdaRemote: boolean // false if LocalStack connection |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Interface for debugging AWS Lambda functions remotely. |
| 38 | + * |
| 39 | + * This interface defines the contract for implementing remote debugging |
| 40 | + * for Lambda functions. |
| 41 | + * |
| 42 | + * Implementations of this interface handle the lifecycle of remote debugging sessions, |
| 43 | + * including checking health, set up, necessary deployment, and later clean up |
| 44 | + */ |
| 45 | +export interface LambdaDebugger { |
| 46 | + checkHealth(): Promise<void> |
| 47 | + setup( |
| 48 | + progress: vscode.Progress<{ message?: string; increment?: number }>, |
| 49 | + functionConfig: Lambda.FunctionConfiguration, |
| 50 | + region: string |
| 51 | + ): Promise<void> |
| 52 | + waitForSetup( |
| 53 | + progress: vscode.Progress<{ message?: string; increment?: number }>, |
| 54 | + functionConfig: Lambda.FunctionConfiguration, |
| 55 | + region: string |
| 56 | + ): Promise<void> |
| 57 | + waitForFunctionUpdates(progress: vscode.Progress<{ message?: string; increment?: number }>): Promise<void> |
| 58 | + cleanup(functionConfig: Lambda.FunctionConfiguration): Promise<void> |
| 59 | +} |
| 60 | + |
| 61 | +// this should be called when the debug session is started |
| 62 | +export async function persistLambdaSnapshot(config: Lambda.FunctionConfiguration | undefined): Promise<void> { |
| 63 | + try { |
| 64 | + await globals.globalState.update(remoteDebugSnapshotString, config) |
| 65 | + } catch (error) { |
| 66 | + // TODO raise toolkit error |
| 67 | + logger.error(`Error persisting debug sessions: ${error}`) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +export function getLambdaSnapshot(): Lambda.FunctionConfiguration | undefined { |
| 72 | + return globals.globalState.get<Lambda.FunctionConfiguration>(remoteDebugSnapshotString) |
| 73 | +} |
0 commit comments