지원 요청을 처리하는 샘플 단계 기능
6979 단어 lambdaawsstepfunction
이 예에서는 AWS Step Functions를 사용하여 호텔 콜 센터에서 객실 예약/취소와 관련된 콜 센터 통화를 처리합니다.
먼저 호출이 진행되는 방법을 보여주는 "상태 머신"의 시각적 표현을 살펴보십시오. 에이전트는 두 단계 중에서 선택할 수 있습니다. 각 단계는 예약 또는 취소 논리를 처리하도록 작성된 람다 함수를 트리거합니다. 예약

AWS Step Functions 상태 머신은 선언적 Amazon States 언어를 사용하여 JSON으로 정의되며, 편집기를 사용하여 상태 머신을 구축하거나 시각적 편집기를 사용하여 도움을 받을 수 있습니다.
그러나 단계 함수를 만들기 전에 워크플로에서 호출할 람다 함수를 만들어야 합니다.
다음과 같이 Python으로 작성된 두 가지 함수가 있습니다.
예약하다
import json
import urllib
import boto3
import datetime
print('Loading function...')
def lambda_handler(message, context):
# input example
# {' TransactionType': 'Reserve'}
#1. Log input message
print("Received message from step Function:")
print(message)
#2. Construct response object
response = {}
response['TransactionType'] = message['TransactionType']
response['Timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%s")
response['Message'] = 'Hello from lambda, I am inside the ProcessReserve function'
return response
취소
import json
import urllib
import boto3
import datetime
print('Loading function...')
def lambda_handler(message, context):
# input example
# {'TransactionType': 'Cancel'}
#1. Log input message
print("Received message from step Function:")
print(message)
#2. Construct response object
response = {}
response['TransactionType'] = message['TransactionType']
response['Timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%s")
response['Message'] = 'Hello from lambda, I am inside the ProcessCancel function'
return response
이제 콘솔에서 AWS Lambda로 이동하여 두 함수를 모두 생성합니다.
"처음부터 작성"을 선택하고 이름을 지정한 다음 코드를 입력하고 "배포"를 클릭합니다.


이제 생성할 "상태 머신"의 코드에 필요하므로 람다 함수 ARN을 복사하는 것을 잊지 마십시오.
여기에서 Step Function 생성을 시작합니다!
AWS Step Function 홈페이지를 열고 왼쪽 상단의 아이콘을 클릭합니다.

왼쪽 창에서 상태 머신을 클릭하고 "상태 머신 만들기"를 클릭합니다.

"워크플로를 시각적으로 디자인"또는 "코드로 워크플로 작성"을 선택할 수 있습니다.
다음 코드를 사용하겠습니다.
{
"Comment": "A simple AWS Step Functions state machine that automates a call center support session.",
"StartAt": "ProcessTransaction",
"States": {
"ProcessTransaction": {
"Type" : "Choice",
"Choices": [
{
"Variable": "$.TransactionType",
"StringEquals": "Reserve",
"Next": "ProcessReserve"
},
{
"Variable": "$.TransactionType",
"StringEquals": "Cancel",
"Next": "ProcessCancel"
}
]
},
"ProcessReserve": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:205057638875:function:Reserve",
"End": true
},
"ProcessCancel": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:205057638875:function:Cancel",
"End": true
}
}
}
계정에서 이를 시도하려면 위 코드의 Lambda 함수 ARN을 자신의 ARN으로 바꿔야 합니다.
"유형"섹션에서는 기본값인 "표준"을 수락하고 "정의"섹션에서는 위의 코드를 삽입합니다. 다음과 같이 보일 것입니다

그런 다음 다음을 클릭합니다.
이름 섹션에서 상태 시스템에 이름을 지정하고 "권한"에 대해 새 "IAM 역할"을 생성합니다.
(상태 머신이 실행 중에 액세스 권한을 갖는 리소스를 정의하는 IAM 역할.)

그런 다음 "상태 머신 만들기"를 클릭합니다.
"AWS 관리형 정책"을 사용하여 생성된 "IAM 역할"을 조사할 수 있습니다.
"IAM 역할 ARN"을 클릭한 다음 권한 탭에서 정책을 클릭하면 여기 내 계정의 정책 JSON 코드가 있습니다. 단계 함수에 람다 함수를 호출할 수 있는 권한을 부여하는 것을 볼 수 있습니다. 용도

이제 단계 함수를 사용할 준비가 되었으며 상태 머신을 사용하여 테스트할 수 있습니다.
다음은 상태 머신입니다.

클릭한 다음 "실행 시작"을 클릭합니다.

다음 코드를 함수에 전달하여 클라이언트를 위한 방 예약으로 안내합니다.
{
"TransactionType": "Reserve"
}
다음과 같이 보일 것입니다

여기에서 실행이 성공한 것을 볼 수 있습니다.

또한 여기에서 "실행 이벤트 내역"을 조사할 수 있습니다.

이것으로 샘플 데모를 마칩니다.
여기에서 AWS Step Functions 사용 사례에 대한 자세한 내용을 읽을 수 있습니다https://aws.amazon.com/step-functions/use-cases/.
읽어주셔서 감사합니다
Reference
이 문제에 관하여(지원 요청을 처리하는 샘플 단계 기능), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/aymanmahmoud33/sample-step-functions-to-handle-a-support-call-4536텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)