diff --git a/README.md b/README.md index 3abbce70..17a977c4 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ The termination handler deployment requires some infrastructure to be setup befo #### 1. Create an SQS Queue: -Here is the AWS CLI command to create an SQS queue to hold termination events from ASG and EC2, although this should really be configured via your favorite infrastructure-as-code tool like CloudFormation or Terraform: +Here is the AWS CLI command to create an SQS queue to hold termination events from ASG and EC2, although this should really be configured via your favorite infrastructure-as-code tool like CloudFormation or Terraform (template describing these resources can be found [here](docs/cfn-template.yaml)): ``` ## Queue Policy @@ -296,7 +296,7 @@ See all the different events docs [here](https://docs.aws.amazon.com/eventbridge You may skip this step if sending events from ASG to SQS directly. -Here are AWS CLI commands to create Amazon EventBridge rules so that ASG termination events, Spot Interruptions, Instance state changes, Rebalance Recommendations, and AWS Health Scheduled Changes are sent to the SQS queue created in the previous step. This should really be configured via your favorite infrastructure-as-code tool like CloudFormation or Terraform: +Here are AWS CLI commands to create Amazon EventBridge rules so that ASG termination events, Spot Interruptions, Instance state changes, Rebalance Recommendations, and AWS Health Scheduled Changes are sent to the SQS queue created in the previous step. This should really be configured via your favorite infrastructure-as-code tool like CloudFormation or Terraform (template describing these resources can be found [here](docs/cfn-template.yaml)): ``` $ aws events put-rule \ diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml new file mode 100644 index 00000000..810674f9 --- /dev/null +++ b/docs/cfn-template.yaml @@ -0,0 +1,79 @@ +AWSTemplateFormatVersion: 2010-09-09 +Resources: + Queue: + Type: 'AWS::SQS::Queue' + Properties: + MessageRetentionPeriod: 300 + QueuePolicy: + Type: 'AWS::SQS::QueuePolicy' + Properties: + Queues: + - !Ref Queue + PolicyDocument: + Statement: + - Effect: Allow + Principal: + Service: + - events.amazonaws.com + - sqs.amazonaws.com + Action: 'sqs:SendMessage' + Resource: !GetAtt Queue.Arn + ASGTermRule: + Type: 'AWS::Events::Rule' + Properties: + EventPattern: + source: + - aws.autoscaling + detail-type: + - EC2 Instance-terminate Lifecycle Action + Targets: + - Id: 1 + Arn: !GetAtt Queue.Arn + ScheduledChangeRule: + Type: 'AWS::Events::Rule' + Properties: + EventPattern: + source: + - aws.health + detail-type: + - AWS Health Event + Targets: + - Id: 1 + Arn: !GetAtt Queue.Arn + SpotTermRule: + Type: 'AWS::Events::Rule' + Properties: + EventPattern: + source: + - aws.ec2 + detail-type: + - EC2 Spot Instance Interruption Warning + Targets: + - Id: 1 + Arn: !GetAtt Queue.Arn + RebalanceRule: + Type: 'AWS::Events::Rule' + Properties: + EventPattern: + source: + - aws.ec2 + detail-type: + - EC2 Instance Rebalance Recommendation + Targets: + - Id: 1 + Arn: !GetAtt Queue.Arn + InstanceStateChangeRule: + Type: 'AWS::Events::Rule' + Properties: + EventPattern: + source: + - aws.ec2 + detail-type: + - EC2 Instance State-change Notification + Targets: + - Id: 1 + Arn: !GetAtt Queue.Arn +Outputs: + QueueURL: + Description: Queue url for AWS NTH controller + Value: !Ref Queue