Amazon EventBridge를 사용하여 AMI 이벤트 모니터링 - Amazon Elastic Compute Cloud

Amazon EventBridge를 사용하여 AMI 이벤트 모니터링

Amazon Machine Image(AMI)의 상태가 변경되면 Amazon EC2는 Amazon EventBridge(이전의 Amazon CloudWatch Events)로 전송되는 이벤트를 생성합니다. 이벤트는 JSON 형식의 기본 EventBridge 이벤트 버스로 전송됩니다. Amazon EventBridge를 사용하여 이러한 이벤트를 감지하고 대응할 수 있습니다. 이벤트에 대한 응답으로 작업을 트리거하는 EventBridge에서 규칙을 생성하여 이를 수행합니다. 예를 들어 AMI 생성 프로세스가 완료된 시점을 감지한 다음 Amazon SNS 주제를 호출하여 사용자에게 이메일 알림을 전송하는 EventBridge 규칙을 생성할 수 있습니다.

AMI가 다음 상태가 되면 Amazon EC2는 EC2 AMI State Change 이벤트를 생성합니다.

  • available

  • failed

  • deregistered

  • disabled

이벤트는 최선의 작업을 기반으로 생성됩니다.

다음 표에는 AMI 작업과 AMI의 가능한 상태가 나열되어 있습니다. 표에서 는 해당 작업이 실행될 때 AMI의 가능한 상태를 나타냅니다.

AMI 작업 available failed deregistered disabled

CopyImage

CreateImage

CreateRestoreImageTask

DeregisterImage

DisableImage

EnableImage

RegisterImage

이벤트 세부 정보

이벤트에서 다음 필드를 사용하여 작업을 트리거하는 규칙을 생성할 수 있습니다.

"source": "aws.ec2"

Amazon EC2에서 시작된 이벤트를 식별합니다.

"detail-type": "EC2 AMI State Change"

이벤트 이름을 식별합니다.

"detail": { "ImageId": "ami-0123456789example", "State": "available", }

AMI ID와 AMI 상태(available, failed, deregistered 또는 disabled)를 제공합니다.

자세한 내용은 Amazon EventBridge 사용 설명서의 다음 섹션을 참조하세요.

Lambda 함수를 생성하고 해당 Lambda 함수를 실행하는 EventBridge 규칙을 생성하는 방법에 대한 튜토리얼은 AWS Lambda 사용자 가이드의 Tutorial: Log the state of an Amazon EC2 instance using EventBridge를 참조하세요.

available 이벤트

다음은 CreateImage, CopyImage, RegisterImage, CreateRestoreImageTask 또는 EnableImage 작업이 성공한 후 AMI가 available 상태가 될 때 Amazon EC2가 생성하는 이벤트의 예입니다.

"State": "available"은 작업이 성공했음을 나타냅니다.

{ "version": "0", "id": "example-9f07-51db-246b-d8b8441bcdf0", "detail-type": "EC2 AMI State Change", "source": "aws.ec2", "account": "012345678901", "time": "yyyy-mm-ddThh:mm:ssZ", "region": "us-east-1", "resources": ["arn:aws:ec2:us-east-1::image/ami-0123456789example"], "detail": { "RequestId": "example-9dcc-40a6-aa77-7ce457d5442b", "ImageId": "ami-0123456789example", "State": "available", "ErrorMessage": "" } }

failed 이벤트

다음은 CreateImage, CopyImage, RegisterImage 또는 CreateRestoreImageTask 작업이 성공한 후 AMI가 failed 상태가 될 때 Amazon EC2가 생성하는 이벤트의 예입니다.

다음 필드는 관련 정보를 제공합니다.

  • "State": "failed" - 작업이 실패했음을 나타냅니다.

  • "ErrorMessage": "" - 실패한 작업의 이유를 제공합니다.

{ "version": "0", "id": "example-9f07-51db-246b-d8b8441bcdf0", "detail-type": "EC2 AMI State Change", "source": "aws.ec2", "account": "012345678901", "time": "yyyy-mm-ddThh:mm:ssZ", "region": "us-east-1", "resources": ["arn:aws:ec2:us-east-1::image/ami-0123456789example"], "detail": { "RequestId": "example-9dcc-40a6-aa77-7ce457d5442b", "ImageId": "ami-0123456789example", "State": "failed", "ErrorMessage": "Description of failure" } }

deregistered 이벤트

다음은 DeregisterImage 작업이 성공한 후 AMI가 deregistered 상태가 될 때 Amazon EC2가 생성하는 이벤트의 예입니다. 작업이 실패하면 이벤트가 생성되지 않습니다. DeregisterImage는 동기 작업이기 때문에 모든 실패는 즉시 알려집니다.

"State": "deregistered"DeregisterImage 작업이 성공했음을 나타냅니다.

{ "version": "0", "id": "example-9f07-51db-246b-d8b8441bcdf0", "detail-type": "EC2 AMI State Change", "source": "aws.ec2", "account": "012345678901", "time": "yyyy-mm-ddThh:mm:ssZ", "region": "us-east-1", "resources": ["arn:aws:ec2:us-east-1::image/ami-0123456789example"], "detail": { "RequestId": "example-9dcc-40a6-aa77-7ce457d5442b", "ImageId": "ami-0123456789example", "State": "deregistered", "ErrorMessage": "" } }

disabled 이벤트

다음은 DisableImage 작업이 성공한 후 AMI가 disabled 상태가 될 때 Amazon EC2가 생성하는 이벤트의 예입니다. 작업이 실패하면 이벤트가 생성되지 않습니다. DisableImage는 동기 작업이기 때문에 모든 실패는 즉시 알려집니다.

"State": "disabled"DisableImage 작업이 성공했음을 나타냅니다.

{ "version": "0", "id": "example-9f07-51db-246b-d8b8441bcdf0", "detail-type": "EC2 AMI State Change", "source": "aws.ec2", "account": "012345678901", "time": "yyyy-mm-ddThh:mm:ssZ", "region": "us-east-1", "resources": ["arn:aws:ec2:us-east-1::image/ami-0123456789example"], "detail": { "RequestId": "example-9dcc-40a6-aa77-7ce457d5442b", "ImageId": "ami-0123456789example", "State": "disabled", "ErrorMessage": "" } }