Skip to content

Commit 5c7fc41

Browse files
authored
feat(lambda): condition check on support lambda managed instance (#8392)
## Problem ## Solution replacing previous check with LMI checks for `CapacityProviderConfig` ## Notice: Lambda SDK version 3.731 doesn't have this field yet. And updating the SDK causes a lot of compatible issue. --- - 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 eb11eb5 commit 5c7fc41

File tree

3 files changed

+67
-58
lines changed

3 files changed

+67
-58
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,10 @@ export class RemoteInvokeWebview extends VueWebview {
284284
await telemetry.lambda_invokeRemote.run(async (span) => {
285285
try {
286286
let funcResponse
287-
const snapStartDisabled =
288-
!this.data.LambdaFunctionNode?.configuration.SnapStart &&
289-
this.data.LambdaFunctionNode?.configuration.State !== 'Active'
287+
const isLMI = (this.data.LambdaFunctionNode?.configuration as any)?.CapacityProviderConfig
290288
if (remoteDebugEnabled) {
291289
funcResponse = await this.clientDebug.invoke(this.data.FunctionArn, input, qualifier)
292-
} else if (snapStartDisabled) {
290+
} else if (isLMI) {
293291
funcResponse = await this.client.invoke(this.data.FunctionArn, input, qualifier, 'None')
294292
} else {
295293
funcResponse = await this.client.invoke(this.data.FunctionArn, input, qualifier, 'Tail')
@@ -300,7 +298,7 @@ export class RemoteInvokeWebview extends VueWebview {
300298
const payload = decodedPayload || JSON.stringify({})
301299

302300
this.channel.appendLine(`Invocation result for ${this.data.FunctionArn}`)
303-
if (!snapStartDisabled) {
301+
if (!isLMI) {
304302
this.channel.appendLine('Logs:')
305303
this.channel.appendLine(logs)
306304
this.channel.appendLine('')

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
:disabled="
5858
!initialData.runtimeSupportsRemoteDebug ||
5959
!initialData.remoteDebugLayer ||
60-
(!initialData.LambdaFunctionNode?.configuration.SnapStart &&
61-
initialData.LambdaFunctionNode?.configuration.State !== 'Active')
60+
(initialData.LambdaFunctionNode?.configuration as any)?.CapacityProviderConfig
6261
"
6362
class="remote-debug-checkbox"
6463
/>
@@ -95,13 +94,10 @@
9594
Region {{ initialData.FunctionRegion }} doesn't support remote debugging yet
9695
</info>
9796
<info
98-
v-else-if="
99-
!initialData.LambdaFunctionNode?.configuration.SnapStart &&
100-
initialData.LambdaFunctionNode?.configuration.State !== 'Active'
101-
"
97+
v-else-if="(initialData.LambdaFunctionNode?.configuration as any)?.CapacityProviderConfig"
10298
style="color: var(--vscode-errorForeground)"
10399
>
104-
Doesn't support remote debugging yet
100+
Lambda Managed Instances Function doesn't support remote debugging yet
105101
</info>
106102
</div>
107103
</div>

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

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,74 @@ import { InvocationResponse } from '@aws-sdk/client-lambda'
1414

1515
describe('RemoteInvokeWebview', function () {
1616
let client: SinonStubbedInstance<LambdaClient>
17-
let remoteInvokeWebview: RemoteInvokeWebview
1817
let outputChannel: vscode.OutputChannel
19-
let mockData: any
20-
before(async () => {
21-
client = createStubInstance(DefaultLambdaClient)
18+
const mockData = {
19+
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:my-function',
20+
} as any
21+
const mockDataLMI = {
22+
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:my-function',
23+
LambdaFunctionNode: {
24+
configuration: {
25+
CapacityProviderConfig: {
26+
blah: 'blah',
27+
},
28+
},
29+
},
30+
} as any
31+
const input = '{"key": "value"}'
32+
const mockResponse = {
33+
LogResult: Buffer.from('Test log').toString('base64'),
34+
Payload: new TextEncoder().encode('{"result": "success"}'),
35+
} satisfies InvocationResponse
36+
37+
before(() => {
2238
outputChannel = {
2339
appendLine: (line: string) => {},
2440
show: () => {},
2541
} as vscode.OutputChannel
26-
mockData = {
27-
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:my-function',
28-
}
29-
remoteInvokeWebview = new RemoteInvokeWebview(outputChannel, client, client, mockData)
3042
})
31-
describe('Invoke Remote Lambda Function with Payload', () => {
32-
it('should invoke with a simple payload', async function () {
33-
const input = '{"key": "value"}'
34-
const mockResponse = {
35-
LogResult: Buffer.from('Test log').toString('base64'),
36-
Payload: new TextEncoder().encode('{"result": "success"}'),
37-
} satisfies InvocationResponse
38-
client.invoke.resolves(mockResponse)
39-
await remoteInvokeWebview.invokeLambda(input)
40-
sinon.assert.calledOnce(client.invoke)
41-
sinon.assert.calledWith(client.invoke, mockData.FunctionArn, input)
42-
})
43+
beforeEach(() => {
44+
client = createStubInstance(DefaultLambdaClient)
45+
})
46+
afterEach(() => {
47+
sinon.restore()
48+
})
49+
it('should invoke with a simple payload', async function () {
50+
const remoteInvokeWebview = new RemoteInvokeWebview(outputChannel, client, client, mockData)
51+
client.invoke.resolves(mockResponse)
52+
await remoteInvokeWebview.invokeLambda(input)
53+
sinon.assert.calledOnce(client.invoke)
54+
sinon.assert.calledWith(client.invoke, mockData.FunctionArn, input, undefined, 'Tail')
4355
})
44-
describe('Invoke Remote Lambda Function with Saved Events Payload', () => {
45-
const mockEvent = {
46-
name: 'TestEvent',
47-
arn: 'arn:aws:lambda:us-west-2:123456789012:function:myFunction',
48-
region: 'us-west-2',
49-
}
50-
const expectedParams = {
51-
name: mockEvent.name,
52-
operation: TestEventsOperation.Get,
53-
functionArn: mockEvent.arn,
54-
region: mockEvent.region,
55-
}
56-
const mockResponse = 'true'
57-
let runSamCliRemoteTestEventsStub: sinon.SinonStub
58-
beforeEach(() => {
59-
runSamCliRemoteTestEventsStub = sinon.stub(samCliRemoteTestEvent, 'runSamCliRemoteTestEvents')
60-
})
61-
afterEach(() => {
62-
sinon.restore()
63-
})
64-
it('should get saved event and invoke with it', async function () {
65-
runSamCliRemoteTestEventsStub.resolves(mockResponse)
66-
await remoteInvokeWebview.getRemoteTestEvents(mockEvent)
6756

68-
sinon.assert.calledOnce(runSamCliRemoteTestEventsStub)
69-
sinon.assert.calledWith(runSamCliRemoteTestEventsStub, expectedParams)
70-
})
57+
it('should invoke with no tail in LMI', async function () {
58+
const remoteInvokeWebview = new RemoteInvokeWebview(outputChannel, client, client, mockDataLMI)
59+
client.invoke.resolves(mockResponse)
60+
await remoteInvokeWebview.invokeLambda(input)
61+
sinon.assert.calledOnce(client.invoke)
62+
sinon.assert.calledWith(client.invoke, mockData.FunctionArn, input, undefined, 'None')
63+
})
64+
65+
const mockEvent = {
66+
name: 'TestEvent',
67+
arn: 'arn:aws:lambda:us-west-2:123456789012:function:myFunction',
68+
region: 'us-west-2',
69+
}
70+
const expectedParams = {
71+
name: mockEvent.name,
72+
operation: TestEventsOperation.Get,
73+
functionArn: mockEvent.arn,
74+
region: mockEvent.region,
75+
}
76+
const mockEventResponse = 'true'
77+
78+
it('should get saved event and invoke with it', async function () {
79+
const remoteInvokeWebview = new RemoteInvokeWebview(outputChannel, client, client, mockData)
80+
const runSamCliRemoteTestEventsStub = sinon.stub(samCliRemoteTestEvent, 'runSamCliRemoteTestEvents')
81+
runSamCliRemoteTestEventsStub.resolves(mockEventResponse)
82+
await remoteInvokeWebview.getRemoteTestEvents(mockEvent)
83+
84+
sinon.assert.calledOnce(runSamCliRemoteTestEventsStub)
85+
sinon.assert.calledWith(runSamCliRemoteTestEventsStub, expectedParams)
7186
})
7287
})

0 commit comments

Comments
 (0)