Skip to content

Commit e07833d

Browse files
authored
refactor(stepfunctions): migrate to sdkv3 (#7560)
## Problem step functions still uses sdk v2 ## Solution - Refactor `DefaultStepFunctionsClient` to `StepFunctionsClient` using ClientWrapper. - Refactor references to `DefaultStepFunctionsClient` with `StepFunctionsClient` and reference sdk v3 types ## Verification - Verified CreateStateMachine, UpdateStateMachine works and creates/updates StateMachine - Verified AWS Explorer lists all StateMachines using ListStateMachine - Verified StartExecution works - Verified TestState, ListIAMRoles works in Workflow Studio, which also fixes the bug that variables cannot be used in TestState in Workflow Studio - fixes #6819 ![TestStateWithVariables](https://github.com/user-attachments/assets/ab981622-b773-4983-a9ce-a70c8fcfc711) --- - 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 0b76f7f commit e07833d

File tree

15 files changed

+638
-114
lines changed

15 files changed

+638
-114
lines changed

package-lock.json

Lines changed: 525 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@
517517
"@aws-sdk/client-ssm": "<3.731.0",
518518
"@aws-sdk/client-sso": "<3.731.0",
519519
"@aws-sdk/client-sso-oidc": "<3.731.0",
520+
"@aws-sdk/client-sfn": "<3.731.0",
520521
"@aws-sdk/credential-provider-env": "<3.731.0",
521522
"@aws-sdk/credential-provider-process": "<3.731.0",
522523
"@aws-sdk/credential-provider-sso": "<3.731.0",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import {
7+
CreateStateMachineCommand,
8+
CreateStateMachineCommandInput,
9+
CreateStateMachineCommandOutput,
10+
DescribeStateMachineCommand,
11+
DescribeStateMachineCommandInput,
12+
DescribeStateMachineCommandOutput,
13+
ListStateMachinesCommand,
14+
ListStateMachinesCommandInput,
15+
ListStateMachinesCommandOutput,
16+
SFNClient,
17+
StartExecutionCommand,
18+
StartExecutionCommandInput,
19+
StartExecutionCommandOutput,
20+
StateMachineListItem,
21+
TestStateCommand,
22+
TestStateCommandInput,
23+
TestStateCommandOutput,
24+
UpdateStateMachineCommand,
25+
UpdateStateMachineCommandInput,
26+
UpdateStateMachineCommandOutput,
27+
} from '@aws-sdk/client-sfn'
28+
import { ClientWrapper } from './clientWrapper'
29+
30+
export class StepFunctionsClient extends ClientWrapper<SFNClient> {
31+
public constructor(regionCode: string) {
32+
super(regionCode, SFNClient)
33+
}
34+
35+
public async *listStateMachines(
36+
request: ListStateMachinesCommandInput = {}
37+
): AsyncIterableIterator<StateMachineListItem> {
38+
do {
39+
const response: ListStateMachinesCommandOutput = await this.makeRequest(ListStateMachinesCommand, request)
40+
if (response.stateMachines) {
41+
yield* response.stateMachines
42+
}
43+
request.nextToken = response.nextToken
44+
} while (request.nextToken)
45+
}
46+
47+
public async getStateMachineDetails(
48+
request: DescribeStateMachineCommandInput
49+
): Promise<DescribeStateMachineCommandOutput> {
50+
return this.makeRequest(DescribeStateMachineCommand, request)
51+
}
52+
53+
public async executeStateMachine(request: StartExecutionCommandInput): Promise<StartExecutionCommandOutput> {
54+
return this.makeRequest(StartExecutionCommand, request)
55+
}
56+
57+
public async createStateMachine(request: CreateStateMachineCommandInput): Promise<CreateStateMachineCommandOutput> {
58+
return this.makeRequest(CreateStateMachineCommand, request)
59+
}
60+
61+
public async updateStateMachine(request: UpdateStateMachineCommandInput): Promise<UpdateStateMachineCommandOutput> {
62+
return this.makeRequest(UpdateStateMachineCommand, request)
63+
}
64+
65+
public async testState(request: TestStateCommandInput): Promise<TestStateCommandOutput> {
66+
return this.makeRequest(TestStateCommand, request)
67+
}
68+
}

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

Lines changed: 0 additions & 79 deletions
This file was deleted.

packages/core/src/stepFunctions/commands/downloadStateMachineDefinition.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import * as nls from 'vscode-nls'
77
import * as os from 'os'
88
const localize = nls.loadMessageBundle()
99

10-
import { StepFunctions } from 'aws-sdk'
10+
import * as StepFunctions from '@aws-sdk/client-sfn'
1111
import * as path from 'path'
1212
import * as vscode from 'vscode'
13-
import { DefaultStepFunctionsClient, StepFunctionsClient } from '../../shared/clients/stepFunctionsClient'
13+
import { StepFunctionsClient } from '../../shared/clients/stepFunctions'
1414

1515
import { getLogger, Logger } from '../../shared/logger/logger'
1616
import { Result } from '../../shared/telemetry/telemetry'
@@ -28,10 +28,11 @@ export async function downloadStateMachineDefinition(params: {
2828
let downloadResult: Result = 'Succeeded'
2929
const stateMachineName = params.stateMachineNode.details.name
3030
try {
31-
const client: StepFunctionsClient = new DefaultStepFunctionsClient(params.stateMachineNode.regionCode)
32-
const stateMachineDetails: StepFunctions.DescribeStateMachineOutput = await client.getStateMachineDetails(
33-
params.stateMachineNode.details.stateMachineArn
34-
)
31+
const client: StepFunctionsClient = new StepFunctionsClient(params.stateMachineNode.regionCode)
32+
const stateMachineDetails: StepFunctions.DescribeStateMachineCommandOutput =
33+
await client.getStateMachineDetails({
34+
stateMachineArn: params.stateMachineNode.details.stateMachineArn,
35+
})
3536

3637
if (params.isPreviewAndRender) {
3738
const doc = await vscode.workspace.openTextDocument({
@@ -53,7 +54,7 @@ export async function downloadStateMachineDefinition(params: {
5354

5455
if (fileInfo) {
5556
const filePath = fileInfo.fsPath
56-
await fs.writeFile(filePath, stateMachineDetails.definition, 'utf8')
57+
await fs.writeFile(filePath, stateMachineDetails.definition || '', 'utf8')
5758
const openPath = vscode.Uri.file(filePath)
5859
const doc = await vscode.workspace.openTextDocument(openPath)
5960
await vscode.window.showTextDocument(doc)

packages/core/src/stepFunctions/commands/publishStateMachine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { load } from 'js-yaml'
77
import * as vscode from 'vscode'
88
import * as nls from 'vscode-nls'
99
import { AwsContext } from '../../shared/awsContext'
10-
import { DefaultStepFunctionsClient, StepFunctionsClient } from '../../shared/clients/stepFunctionsClient'
10+
import { StepFunctionsClient } from '../../shared/clients/stepFunctions'
1111
import { getLogger, Logger } from '../../shared/logger/logger'
1212
import { showViewLogsMessage } from '../../shared/utilities/messages'
1313
import { VALID_SFN_PUBLISH_FORMATS, YAML_FORMATS } from '../constants/aslFormats'
@@ -64,7 +64,7 @@ export async function publishStateMachine(params: publishStateMachineParams) {
6464
if (!response) {
6565
return
6666
}
67-
const client = new DefaultStepFunctionsClient(response.region)
67+
const client = new StepFunctionsClient(response.region)
6868

6969
if (response?.createResponse) {
7070
await createStateMachine(response.createResponse, text, params.outputChannel, response.region, client)
@@ -109,7 +109,7 @@ async function createStateMachine(
109109
wizardResponse.name
110110
)
111111
)
112-
outputChannel.appendLine(result.stateMachineArn)
112+
outputChannel.appendLine(result.stateMachineArn || '')
113113
logger.info(`Created "${result.stateMachineArn}"`)
114114
} catch (err) {
115115
const msg = localize(

packages/core/src/stepFunctions/explorer/stepFunctionsNodes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import * as os from 'os'
77
import * as nls from 'vscode-nls'
88
const localize = nls.loadMessageBundle()
99

10-
import { StepFunctions } from 'aws-sdk'
10+
import * as StepFunctions from '@aws-sdk/client-sfn'
1111
import * as vscode from 'vscode'
12-
import { DefaultStepFunctionsClient } from '../../shared/clients/stepFunctionsClient'
12+
import { StepFunctionsClient } from '../../shared/clients/stepFunctions'
1313

1414
import { AWSResourceNode } from '../../shared/treeview/nodes/awsResourceNode'
1515
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
@@ -40,7 +40,7 @@ export class StepFunctionsNode extends AWSTreeNodeBase {
4040

4141
public constructor(
4242
public override readonly regionCode: string,
43-
private readonly client = new DefaultStepFunctionsClient(regionCode)
43+
private readonly client = new StepFunctionsClient(regionCode)
4444
) {
4545
super('Step Functions', vscode.TreeItemCollapsibleState.Collapsed)
4646
this.stateMachineNodes = new Map<string, StateMachineNode>()
@@ -101,7 +101,7 @@ export class StateMachineNode extends AWSTreeNodeBase implements AWSResourceNode
101101
}
102102

103103
public get arn(): string {
104-
return this.details.stateMachineArn
104+
return this.details.stateMachineArn || ''
105105
}
106106

107107
public get name(): string {

packages/core/src/stepFunctions/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import * as nls from 'vscode-nls'
66
const localize = nls.loadMessageBundle()
77

8-
import { StepFunctions } from 'aws-sdk'
8+
import * as StepFunctions from '@aws-sdk/client-sfn'
99
import * as yaml from 'js-yaml'
1010
import * as vscode from 'vscode'
11-
import { StepFunctionsClient } from '../shared/clients/stepFunctionsClient'
11+
import { StepFunctionsClient } from '../shared/clients/stepFunctions'
1212
import {
1313
DiagnosticSeverity,
1414
DocumentLanguageSettings,

packages/core/src/stepFunctions/vue/executeStateMachine/executeStateMachine.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vscode-nls'
77
const localize = nls.loadMessageBundle()
88

9-
import { DefaultStepFunctionsClient } from '../../../shared/clients/stepFunctionsClient'
9+
import { StepFunctionsClient } from '../../../shared/clients/stepFunctions'
1010

1111
import { getLogger } from '../../../shared/logger/logger'
1212
import { Result } from '../../../shared/telemetry/telemetry'
@@ -56,11 +56,14 @@ export class ExecuteStateMachineWebview extends VueWebview {
5656
this.channel.appendLine('')
5757

5858
try {
59-
const client = new DefaultStepFunctionsClient(this.stateMachine.region)
60-
const startExecResponse = await client.executeStateMachine(this.stateMachine.arn, input)
59+
const client = new StepFunctionsClient(this.stateMachine.region)
60+
const startExecResponse = await client.executeStateMachine({
61+
stateMachineArn: this.stateMachine.arn,
62+
input,
63+
})
6164
this.logger.info('started execution for Step Functions State Machine')
6265
this.channel.appendLine(localize('AWS.stepFunctions.executeStateMachine.info.started', 'Execution started'))
63-
this.channel.appendLine(startExecResponse.executionArn)
66+
this.channel.appendLine(startExecResponse.executionArn || '')
6467
} catch (e) {
6568
executeResult = 'Failed'
6669
const error = e as Error
@@ -82,8 +85,8 @@ const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
8285

8386
export async function executeStateMachine(context: ExtContext, node: StateMachineNode): Promise<void> {
8487
const wv = new Panel(context.extensionContext, context.outputChannel, {
85-
arn: node.details.stateMachineArn,
86-
name: node.details.name,
88+
arn: node.details.stateMachineArn || '',
89+
name: node.details.name || '',
8790
region: node.regionCode,
8891
})
8992

packages/core/src/stepFunctions/wizards/publishStateMachineWizard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Wizard, WIZARD_BACK } from '../../shared/wizards/wizard'
2222
import { isStepFunctionsRole } from '../utils'
2323
import { createRolePrompter } from '../../shared/ui/common/roles'
2424
import { IamClient } from '../../shared/clients/iam'
25-
import { DefaultStepFunctionsClient } from '../../shared/clients/stepFunctionsClient'
25+
import { StepFunctionsClient } from '../../shared/clients/stepFunctions'
2626

2727
export enum PublishStateMachineAction {
2828
QuickCreate,
@@ -109,14 +109,14 @@ function createStepFunctionsRolePrompter(region: string) {
109109
}
110110

111111
async function* listStateMachines(region: string) {
112-
const client = new DefaultStepFunctionsClient(region)
112+
const client = new StepFunctionsClient(region)
113113

114114
for await (const machine of client.listStateMachines()) {
115115
yield [
116116
{
117-
label: machine.name,
118-
data: machine.stateMachineArn,
119-
description: machine.stateMachineArn,
117+
label: machine.name || '',
118+
data: machine.stateMachineArn || '',
119+
description: machine.stateMachineArn || '',
120120
},
121121
]
122122
}

0 commit comments

Comments
 (0)