Skip to content
Closed
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
5 changes: 4 additions & 1 deletion packages/core/src/lambda/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { liveTailRegistry, liveTailCodeLensProvider } from '../awsService/cloudW
import { getFunctionLogGroupName } from '../awsService/cloudWatchLogs/activation'
import { ToolkitError, isError } from '../shared/errors'
import { LogStreamFilterResponse } from '../awsService/cloudWatchLogs/wizard/liveTailLogStreamSubmenu'
import { registerLambdaUriHandler } from './uriHandlers'

/**
* Activates Lambda components.
Expand Down Expand Up @@ -116,6 +117,8 @@ export async function activate(context: ExtContext): Promise<void> {
throw err
}
}
})
}),

registerLambdaUriHandler()
)
}
44 changes: 44 additions & 0 deletions packages/core/src/lambda/uriHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import * as nls from 'vscode-nls'

import { SearchParams } from '../shared/vscode/uriHandler'
import { showConfirmationMessage } from '../shared/utilities/messages'
import globals from '../shared/extensionGlobals'
import { VSCODE_EXTENSION_ID } from '../shared/extensions'

const localize = nls.loadMessageBundle()

export function registerLambdaUriHandler() {
async function openFunctionHandler(params: ReturnType<typeof parseOpenParams>) {
const response = await showConfirmationMessage({
prompt: localize(
'AWS.lambda.uriUnavailable',
'The URI you are attempting to access is not in this version of the Toolkit'
),
confirm: localize('AWS.installLatest', 'Install latest'),
})
if (response) {
await vscode.commands.executeCommand('extension.open', VSCODE_EXTENSION_ID.awstoolkit)
}
}

return vscode.Disposable.from(
globals.uriHandler.onPath('/lambda/load-function', openFunctionHandler, parseOpenParams)
Copy link
Contributor

@justinmk3 justinmk3 Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for re-using the existing module and patterns.

)
}

export function parseOpenParams(query: SearchParams) {
return {
functionName: query.getOrThrow(
'functionName',
localize('AWS.lambda.open.missingName', 'A function name must be provided')
),
region: query.getOrThrow('region', localize('AWS.lambda.open.missingRegion', 'A region must be provided')),
isCfn: query.get('isCfn'),
}
}
36 changes: 36 additions & 0 deletions packages/core/src/test/lambda/uriHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'assert'
import { SearchParams } from '../../shared/vscode/uriHandler'
import { parseOpenParams } from '../../lambda/uriHandlers'
import { globals } from '../../shared'

describe('Lambda URI Handler', function () {
describe('load-function', function () {
it('registers for "/lambda/load-function"', function () {
assert.throws(() => globals.uriHandler.onPath('/lambda/load-function', () => {}))
})

it('parses parameters', function () {
let query = new SearchParams({
functionName: 'example',
})
assert.throws(() => parseOpenParams(query), /A region must be provided/)
query = new SearchParams({
region: 'example',
})
assert.throws(() => parseOpenParams(query), /A function name must be provided/)

const valid = {
functionName: 'example',
region: 'example',
isCfn: 'false',
}
query = new SearchParams(valid)
assert.deepEqual(parseOpenParams(query), valid)
})
})
})
Loading