AWS SAM에서 EventBridge 스케줄러를 사용하여 시간 기반 이벤트 관리 - AWS Serverless Application Model

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS SAM에서 EventBridge 스케줄러를 사용하여 시간 기반 이벤트 관리

이 주제의 내용에서는 Amazon EventBridge Scheduler의 정의, AWS SAM이 제공하는 지원 내용, Scheduler 이벤트를 생성하는 방법 및 Scheduler 이벤트를 생성할 때 참조할 수 있는 예제에 대한 세부 정보를 제공합니다.

Amazon EventBridge Scheduler란 무엇인가요?

EventBridge 스케줄러를 사용하여 AWS SAM 템플릿에서 이벤트를 예약합니다. Amazon EventBridge Scheduler는 모든 AWS 서비스에서 수천만 개의 이벤트와 태스크를 생성, 시작 및 관리할 수 있는 일정 관리 서비스입니다. 이 서비스는 시간 관련 이벤트에 특히 유용합니다. 이를 사용하여 이벤트 및 반복적인 시간 기반 호출을 예약할 수 있습니다. 또한 일회성 이벤트와 시작 및 종료 시간이 있는 비율 및 시간 표현식을 지원합니다.

Amazon EventBridge Scheduler에 대한 자세한 내용은 EventBridge Scheduler 사용 설명서Amazon EventBridge Scheduler란 무엇인가요?를 참조하세요.

AWS SAM의 EventBridge Scheduler 지원

AWS Serverless Application Model(AWS SAM) 템플릿 사양은 AWS Lambda 및 AWS Step Functions에 관한 EventBridge 스케줄러에서 이벤트를 스케줄링하는 데 사용할 수 있는 간단하고 간단한 명령문 제공.

AWS SAM에서 EventBridge 스케줄러 이벤트 생성

ScheduleV2 속성을 AWS SAM 템플릿의 이벤트 유형으로 설정하여 EventBridge 스케줄러 이벤트를 정의합니다. 이 속성은 AWS::Serverless::FunctionAWS::Serverless::StateMachine 리소스 유형을 지원합니다.

MyFunction: Type: AWS::Serverless::Function Properties: Events: CWSchedule: Type: ScheduleV2 Properties: ScheduleExpression: 'rate(1 minute)' Name: TestScheduleV2Function Description: Test schedule event MyStateMachine: Type: AWS::Serverless::StateMachine Properties: Events: CWSchedule: Type: ScheduleV2 Properties: ScheduleExpression: 'rate(1 minute)' Name: TestScheduleV2StateMachine Description: Test schedule event

EventBridge 스케줄러 이벤트 스케줄링은 처리되지 않은 이벤트에 대한 DLQ(Dead Letter Queue)도 지원합니다. dead-letter 대기열에 대한 자세한 내용은 EventBridge 스케줄러 사용자 가이드EventBridge 스케줄러용 DLQ 대기열 구성을 참조하세요.

DLQ ARN이 지정되면 AWS SAM는 스케줄러 스케줄에서 DLQ로 메시지를 전송할 수 있는 권한을 구성합니다. DLQ ARN이 지정되지 않은 경우 AWS SAM은 DLQ 리소스를 생성합니다.

예시

AWS SAM을 사용하여 EventBridge 스케줄러 이벤트를 정의하는 기본 예제

Transform: AWS::Serverless-2016-10-31 Resources: MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.8 InlineCode: | def handler(event, context): print(event) return {'body': 'Hello World!', 'statusCode': 200} MemorySize: 128 Events: Schedule: Type: ScheduleV2 Properties: ScheduleExpression: rate(1 minute) Input: '{"hello": "simple"}' MySFNFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.8 InlineCode: | def handler(event, context): print(event) return {'body': 'Hello World!', 'statusCode': 200} MemorySize: 128 StateMachine: Type: AWS::Serverless::StateMachine Properties: Type: STANDARD Definition: StartAt: MyLambdaState States: MyLambdaState: Type: Task Resource: !GetAtt MySFNFunction.Arn End: true Policies: - LambdaInvokePolicy: FunctionName: !Ref MySFNFunction Events: Schedule: Type: ScheduleV2 Properties: ScheduleExpression: rate(1 minute) Input: '{"hello": "simple"}'

자세히 알아보기

ScheduleV2 EventBridge 스케줄러 속성을 정의하는 방법에 대한 자세한 내용은 다음을 참조하세요.