Skip to content

kyopark2014/aws-step-functions

Repository files navigation

AWS Step Functions

여기에서는 Step Functions 사용 방법 및 CDK deployment에 대해 설명합니다.

Step Functions 란?

Business Logic을 구현하기 위하여, 어떤 서비스가 어떤 Request 시작하면, 필연적으로 재시도, 실패시 예외처리가 필요합니다. 또한 어떤 business logic은 여러 step을 거쳐서 동작하므로 이를 여러개의 모듈 또는 lambda로 구현하는것은 꽤 번거로운 작업입니다. 이러한 workflow를 모듈화하여 visual하게 처리하고, 관리가 필요없는 serverless로 제공한다면, 복잡하게 서비스를 생성하는 것보다 개발기간을 단축하고, 버그나 수정 필요시 빠르게 대응할 수 있습니다.

AWS Step Functions은 low-code visual workflow service입니다. 즉, 최소한의 코드로 workflow를 생성하여 상기의 복잡한 작업을 수행 할 수 있습니다. 또한, AWS의 각종 데이터베이스, ML 서비스들과 쉽게 integration이 가능하므로 빠르게 원하는 work를 수행할 수 있습니다.

활용 케이스

Step Function Case Study에서는 Step Fucntions 활용방안에 대해 설명합니다.

Wait for Callback에서는 사람의 승인을 필요로 하거나, 다른 시스템에서 trigger될때까지 기다리게 하기 위한 Step Functions 구현 예제입니다.

IaC를 이용한 인프라 생성하기

CloudFormation으로 Step Functions 만들기를 따라서 CloudFormation으로 인프라 생성이 가능합니다.

CDK - Step Functions에서는 AWS CDK로 Step Function과 API Gateway를 생성하여 https API로 Step Function을 호출할 수 있음을 보여줍니다.

CDK를 이용하여 Lambda를 포함한 Step Function 생성에서는 3개의 Lambda를 이용해 구현한 Step Function 입니다.

Step Functions으로 DynamoDB에 Item 저장하기

Step Functions - DynamoDB는 Step Functions로 DynamoDB에 Item 저장하는 예제입니다.

S3 Trigger

S3 bucket에서 발생하는 Event Notification을 Step function과 연결할 수 있습니다.

이것은 S3 - EventBridge - Step Function로 구성할 수 있습니다. S3 - Lambda - Step Function으로도 구성할 수 있지만, EventBridge를 사용하면 더 flexible하고 cost effective하고 lower latency를 가집니다.

이를 CDK로는 아래와 같이 구성합니다.

import { Construct } from 'constructs';
import { Stack, StackProps } from 'aws-cdk-lib';
import { S3ToStepfunctions, S3ToStepfunctionsProps } from '@aws-solutions-constructs/aws-s3-stepfunctions';
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';

const startState = new stepfunctions.Pass(this, 'StartState');

new S3ToStepfunctions(this, 'test-s3-stepfunctions-stack', {
    stateMachineProps: {
      definition: startState
    }
});

Summary

States

  • Task: Execute work. This represents an operation to execute, it's integrable directly with a Lambda Invoke, or you can specify parameters that call a specific AWS service

  • Choice: Add branching logic. It is possible to configure a condition that permits the user to change execution flow based on the output of the previous state

  • Wait: Add a timed delay. It's possible to suspend the machine execution for a specific time

  • Parallel: Execute branches in parallel. This permits the execution of a state set that will be executed in parallel, using a single input value.

  • Map: Process each of an input array's items with a state machine. This permits the execution of a state set, using an array of input for each state.

  • Success: Signal a successful execution and stop. When a machine execution finishes with success

  • Fail: Signal a failed execution and stop. When a machine execution finishes with some errors

  • Pass: Pass input to output. This state passes its input to its output, without performing work. Pass states are useful when constructing and debugging state machines.

Integration syntax

arn:aws:states:::aws-sdk:serviceName:apiAction.[serviceIntegrationPattern]

예제는 아래와 같습니다.

arn:aws:sates:::aws-sdk:ec2:describeInstances

Express Workflow

Express Workflow에서는 express로 workflow 구성하는것에 대해 설명합니다.

Synchronous

Execute synchronous task와 같이 Resouce arn에 ".sync"를 붙여서, synchronous task를 생성 할 수 있습니다.

image

Workshop

The AWS Step Functions Workshop을 이용해 Workshop을 해볼수 있습니다.

Amazon States Language (ASL)

Step Function에서는 ASL을 이용하여 workflow를 생성합니다.

References

aws-stepfunctions-examples

AWS Step Functions을 통한 마이크로서비스 오케스트레이션 - 강세용:: AWS 현대적 애플리케이션 개발

Step Function with AWS CDK in action: our points of view about it using Typescript

About

It explains how to use step fuctions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published