Last active
June 21, 2021 02:56
-
-
Save press0/15a8ec483c6c546da3242e0488e32ddd to your computer and use it in GitHub Desktop.
AWS CW Rule to detect Glue Job failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ref https://gnomezgrave.com/2020/01/26/get-notified-on-aws-glue-job-failures/ | |
Resources: | |
MyGlueJobFailEvent: | |
Type: AWS::Events::Rule | |
Properties: | |
Description: This rule is to detect if the Glue Jobs fails | |
EventPattern: | |
source: | |
- aws.glue | |
detail-type: | |
# It should be exactly like this. | |
- Glue Job State Change | |
detail: | |
jobName: | |
- !Ref MyGlueJob | |
- my-other-glue-job-name | |
state: | |
- FAILED | |
Name: !Sub | |
- ${StackName}-fail-event | |
- { StackName: !Ref "AWS::StackName" } | |
State: ENABLED | |
Targets: | |
- Arn: arn-of-my-sns-topic | |
"Id": "SNS-ID" | |
AlarmTopic: | |
Type: AWS::SNS::Topic | |
Properties: | |
TopicName: !Sub | |
- ${StackName}--alarms-topic | |
- { StackName: !Ref "AWS::StackName" } | |
DisplayName: !Sub | |
- ${StackName}--alarms-topic | |
- { StackName: !Ref "AWS::StackName" } | |
AlarmTopicPolicy: | |
Type: AWS::SNS::TopicPolicy | |
Properties: | |
PolicyDocument: | |
Version: '2012-10-17' | |
Id: CloudWatchEvents | |
Statement: | |
- Sid: EventsToSNS | |
# This Statement allows CW Events to push messages to SNS | |
Effect: Allow | |
Principal: | |
Service: events.amazonaws.com | |
Action: SNS:Publish | |
Resource: !Ref AlarmTopic | |
- Sid: DefaultSNS | |
# This is the default Statement | |
Effect: Allow | |
Principal: | |
AWS: "*" | |
Action: | |
- SNS:GetTopicAttributes | |
- SNS:SetTopicAttributes | |
- SNS:AddPermission | |
- SNS:RemovePermission | |
- SNS:DeleteTopic | |
- SNS:Subscribe | |
- SNS:ListSubscriptionsByTopic | |
- SNS:Publish | |
- SNS:Receive | |
Resource: !Ref AlarmTopic | |
Condition: | |
StringEquals: | |
AWS:SourceOwner: !Ref "AWS::AccountId" | |
Topics: | |
- !Ref AlarmTopic | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment