Skip to content

Commit f1a93d1

Browse files
authored
feat(lambda): Update log --tail in remote invoke (#8357)
## Problem ## Solution Disable log --tail in non snap start functions --- - 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](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ab5a282 commit f1a93d1

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

packages/core/src/lambda/vue/remoteInvoke/invokeLambda.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,28 @@ export class RemoteInvokeWebview extends VueWebview {
283283
this.channel.appendLine('Loading response...')
284284
await telemetry.lambda_invokeRemote.run(async (span) => {
285285
try {
286-
const funcResponse = remoteDebugEnabled
287-
? await this.clientDebug.invoke(this.data.FunctionArn, input, qualifier)
288-
: await this.client.invoke(this.data.FunctionArn, input, qualifier)
286+
let funcResponse
287+
const snapStartDisabled =
288+
!this.data.LambdaFunctionNode?.configuration.SnapStart &&
289+
this.data.LambdaFunctionNode?.configuration.State !== 'Active'
290+
if (remoteDebugEnabled) {
291+
funcResponse = await this.clientDebug.invoke(this.data.FunctionArn, input, qualifier)
292+
} else if (snapStartDisabled) {
293+
funcResponse = await this.client.invoke(this.data.FunctionArn, input, qualifier, 'None')
294+
} else {
295+
funcResponse = await this.client.invoke(this.data.FunctionArn, input, qualifier, 'Tail')
296+
}
297+
289298
const logs = funcResponse.LogResult ? decodeBase64(funcResponse.LogResult) : ''
290299
const decodedPayload = funcResponse.Payload ? new TextDecoder().decode(funcResponse.Payload) : ''
291300
const payload = decodedPayload || JSON.stringify({})
292301

293302
this.channel.appendLine(`Invocation result for ${this.data.FunctionArn}`)
294-
this.channel.appendLine('Logs:')
295-
this.channel.appendLine(logs)
296-
this.channel.appendLine('')
303+
if (!snapStartDisabled) {
304+
this.channel.appendLine('Logs:')
305+
this.channel.appendLine(logs)
306+
this.channel.appendLine('')
307+
}
297308
this.channel.appendLine('Payload:')
298309
this.channel.appendLine(String(payload))
299310
this.channel.appendLine('')

packages/core/src/shared/clients/lambdaClient.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ export class DefaultLambdaClient {
6666
)
6767
}
6868

69-
public async invoke(name: string, payload?: BlobPayloadInputTypes, version?: string): Promise<InvocationResponse> {
69+
public async invoke(
70+
name: string,
71+
payload?: BlobPayloadInputTypes,
72+
version?: string,
73+
logtype: 'Tail' | 'None' = 'Tail'
74+
): Promise<InvocationResponse> {
7075
const sdkClient = await this.createSdkClient()
7176

7277
const response = await sdkClient.send(
7378
new InvokeCommand({
7479
FunctionName: name,
75-
LogType: 'Tail',
80+
LogType: logtype,
7681
Payload: payload,
7782
Qualifier: version,
7883
})

packages/core/src/test/lambda/vue/remoteInvoke/invokeLambda.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ describe('RemoteInvokeWebview', () => {
4242
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
4343
FunctionRegion: 'us-west-2',
4444
InputSamples: [],
45+
LambdaFunctionNode: {
46+
configuration: {
47+
State: 'Active',
48+
},
49+
} as LambdaFunctionNode,
4550
} as InitialData
4651

4752
remoteInvokeWebview = new RemoteInvokeWebview(outputChannel, client, client, data)
@@ -53,6 +58,11 @@ describe('RemoteInvokeWebview', () => {
5358
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
5459
FunctionRegion: 'us-west-2',
5560
InputSamples: [],
61+
LambdaFunctionNode: {
62+
configuration: {
63+
State: 'Active',
64+
},
65+
} as LambdaFunctionNode,
5666
}
5767
const result = remoteInvokeWebview.init()
5868
assert.deepEqual(result, mockData)
@@ -74,7 +84,7 @@ describe('RemoteInvokeWebview', () => {
7484

7585
await remoteInvokeWebview.invokeLambda(input)
7686
assert(client.invoke.calledOnce)
77-
assert(client.invoke.calledWith(data.FunctionArn, input))
87+
assert(client.invoke.calledWith(data.FunctionArn, input, sinon.match.any, 'Tail'))
7888
assert.deepStrictEqual(appendedLines, [
7989
'Loading response...',
8090
'Invocation result for arn:aws:lambda:us-west-2:123456789012:function:testFunction',

0 commit comments

Comments
 (0)