Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDKs 코드 예제
다음 코드 예제에서는 AWS 소프트웨어 개발 키트(SDK)와 AWS Step Functions 함께를 사용하는 방법을 보여줍니다.
기본 사항은 서비스 내에서 필수 작업을 수행하는 방법을 보여주는 코드 예제입니다.
작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 관련 시나리오의 컨텍스트에 따라 표시되며, 개별 서비스 함수를 직접적으로 호출하는 방법을 보여줍니다.
시나리오는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.
시작
다음 코드 예제에서는 Step Functions를 사용하여 시작하는 방법을 보여 줍니다.
- .NET
-
- AWS SDK for .NET
-
namespace StepFunctionsActions;
using Amazon.StepFunctions;
using Amazon.StepFunctions.Model;
public class HelloStepFunctions
{
static async Task Main()
{
var stepFunctionsClient = new AmazonStepFunctionsClient();
Console.Clear();
Console.WriteLine("Welcome to AWS Step Functions");
Console.WriteLine("Let's list up to 10 of your state machines:");
var stateMachineListRequest = new ListStateMachinesRequest { MaxResults = 10 };
// Get information for up to 10 Step Functions state machines.
var response = await stepFunctionsClient.ListStateMachinesAsync(stateMachineListRequest);
if (response.StateMachines.Count > 0)
{
response.StateMachines.ForEach(stateMachine =>
{
Console.WriteLine($"State Machine Name: {stateMachine.Name}\tAmazon Resource Name (ARN): {stateMachine.StateMachineArn}");
});
}
else
{
Console.WriteLine("\tNo state machines were found.");
}
}
}
- Java
-
- SDK for Java 2.x
-
Hello의 Java 버전.
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sfn.SfnClient;
import software.amazon.awssdk.services.sfn.model.ListStateMachinesResponse;
import software.amazon.awssdk.services.sfn.model.SfnException;
import software.amazon.awssdk.services.sfn.model.StateMachineListItem;
import java.util.List;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class ListStateMachines {
public static void main(String[] args) {
Region region = Region.US_EAST_1;
SfnClient sfnClient = SfnClient.builder()
.region(region)
.build();
listMachines(sfnClient);
sfnClient.close();
}
public static void listMachines(SfnClient sfnClient) {
try {
ListStateMachinesResponse response = sfnClient.listStateMachines();
List<StateMachineListItem> machines = response.stateMachines();
for (StateMachineListItem machine : machines) {
System.out.println("The name of the state machine is: " + machine.name());
System.out.println("The ARN value is : " + machine.stateMachineArn());
}
} catch (SfnException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
}
- Kotlin
-
- SDK for Kotlin
-
import aws.sdk.kotlin.services.sfn.SfnClient
import aws.sdk.kotlin.services.sfn.model.ListStateMachinesRequest
/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main() {
println(DASHES)
println("Welcome to the AWS Step Functions Hello example.")
println("Lets list up to ten of your state machines:")
println(DASHES)
listMachines()
}
suspend fun listMachines() {
SfnClient { region = "us-east-1" }.use { sfnClient ->
val response = sfnClient.listStateMachines(ListStateMachinesRequest {})
response.stateMachines?.forEach { machine ->
println("The name of the state machine is ${machine.name}")
println("The ARN value is ${machine.stateMachineArn}")
}
}
}
- Python
-
- SDK for Python (Boto3)
-
import boto3
def hello_stepfunctions(stepfunctions_client):
"""
Use the AWS SDK for Python (Boto3) to create an AWS Step Functions client and list
the state machines in your account. This list might be empty if you haven't created
any state machines.
This example uses the default settings specified in your shared credentials
and config files.
:param stepfunctions_client: A Boto3 Step Functions Client object.
"""
print("Hello, Step Functions! Let's list up to 10 of your state machines:")
state_machines = stepfunctions_client.list_state_machines(maxResults=10)
for sm in state_machines["stateMachines"]:
print(f"\t{sm['name']}: {sm['stateMachineArn']}")
if __name__ == "__main__":
hello_stepfunctions(boto3.client("stepfunctions"))