Skip to content

Commit 7dac682

Browse files
zelzhouDiler Zaza
authored andcommitted
refactor(stepfunctions): migrate to sdkv3 (#7560)
step functions still uses sdk v2 - Refactor `DefaultStepFunctionsClient` to `StepFunctionsClient` using ClientWrapper. - Refactor references to `DefaultStepFunctionsClient` with `StepFunctionsClient` and reference sdk v3 types - 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 a5e950c commit 7dac682

File tree

15 files changed

+684
-181
lines changed

15 files changed

+684
-181
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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
StopExecutionCommand,
21+
StopExecutionCommandInput,
22+
StopExecutionCommandOutput,
23+
RedriveExecutionCommand,
24+
RedriveExecutionCommandInput,
25+
RedriveExecutionCommandOutput,
26+
GetExecutionHistoryCommand,
27+
GetExecutionHistoryCommandInput,
28+
GetExecutionHistoryCommandOutput,
29+
GetMapRunCommand,
30+
GetMapRunCommandInput,
31+
GetMapRunCommandOutput,
32+
DescribeExecutionCommand,
33+
DescribeExecutionCommandInput,
34+
DescribeExecutionCommandOutput,
35+
DescribeStaeMachineForExecutionCmmand,
36+
DescribeStateMachineForExecutionCommandInput,
37+
DescribeStateMachineForExecutionCommandOutput,
38+
StateMachineListItem,
39+
TestStateCommand,
40+
TestStateCommandInput,
41+
TestStateCommandOutput,
42+
UpdateStateMachineCommand,
43+
UpdateStateMachineCommandInput,
44+
UpdateStateMachineCommandOutput,
45+
} from '@aws-sdk/client-sfn'
46+
import { ClientWrapper } from './clientWrapper'
47+
48+
export class StepFunctionsClient extends ClientWrapper<SFNClient> {
49+
public constructor(regionCode: string) {
50+
super(regionCode, SFNClient)
51+
}
52+
53+
public async *listStateMachines(
54+
request: ListStateMachinesCommandInput = {}
55+
): AsyncIterableIterator<StateMachineListItem> {
56+
do {
57+
const response: ListStateMachinesCommandOutput = await this.makeRequest(ListStateMachinesCommand, request)
58+
if (response.stateMachines) {
59+
yield* response.stateMachines
60+
}
61+
request.nextToken = response.nextToken
62+
} while (request.nextToken)
63+
}
64+
65+
public async getStateMachineDetails(
66+
request: DescribeStateMachineCommandInput
67+
): Promise<DescribeStateMachineCommandOutput> {
68+
return this.makeRequest(DescribeStateMachineCommand, request)
69+
}
70+
71+
public async getStateMachineDetailsForExecution(
72+
request: DescribeStateMachineForExecutionCommandInput
73+
): Promise<DescribeStateMachineForExecutionCommandOutput> {
74+
return this.makeRequest(DescribeStaeMachineForExecutionCmmand, request)
75+
}
76+
77+
public async getExecutionDetails(request: DescribeExecutionCommandInput): Promise<DescribeExecutionCommandOutput> {
78+
return this.makeRequest(DescribeExecutionCommand, request)
79+
}
80+
81+
public async getMapRunDetails(request: GetMapRunCommandInput): Promise<GetMapRunCommandOutput> {
82+
return this.makeRequest(GetMapRunCommand, request)
83+
}
84+
85+
public async getExecutionHistory(
86+
request: GetExecutionHistoryCommandInput
87+
): Promise<GetExecutionHistoryCommandOutput> {
88+
return this.makeRequest(GetExecutionHistoryCommand, request)
89+
}
90+
91+
public async reDriveExecution(request: RedriveExecutionCommandInput): Promise<RedriveExecutionCommandOutput> {
92+
return this.makeRequest(RedriveExecutionCommand, request)
93+
}
94+
95+
public async stopExecution(request: StopExecutionCommandInput): Promise<StopExecutionCommandOutput> {
96+
return this.makeRequest(StopExecutionCommand, request)
97+
}
98+
99+
public async executeStateMachine(request: StartExecutionCommandInput): Promise<StartExecutionCommandOutput> {
100+
return this.makeRequest(StartExecutionCommand, request)
101+
}
102+
103+
public async createStateMachine(request: CreateStateMachineCommandInput): Promise<CreateStateMachineCommandOutput> {
104+
return this.makeRequest(CreateStateMachineCommand, request)
105+
}
106+
107+
public async updateStateMachine(request: UpdateStateMachineCommandInput): Promise<UpdateStateMachineCommandOutput> {
108+
return this.makeRequest(UpdateStateMachineCommand, request)
109+
}
110+
111+
public async testState(request: TestStateCommandInput): Promise<TestStateCommandOutput> {
112+
return this.makeRequest(TestStateCommand, request)
113+
}
114+
}

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

Lines changed: 0 additions & 146 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,

0 commit comments

Comments
 (0)