From d9a8171ea72c9dea7ee86dc12a230e746d04c07c Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Wed, 16 Mar 2022 19:14:29 +0530 Subject: [PATCH 01/10] CFN Templates added CFN Templates added for the queue and event subscription --- docs/cfn-template.yaml | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docs/cfn-template.yaml diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml new file mode 100644 index 00000000..64e16731 --- /dev/null +++ b/docs/cfn-template.yaml @@ -0,0 +1,68 @@ +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 + 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: Url used by AWS NTH controller + Value: !Ref Queue From 94155893388b68ecf0604b36756606e2cbb031a4 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Wed, 16 Mar 2022 20:33:04 +0530 Subject: [PATCH 02/10] Update cfn-template.yaml --- docs/cfn-template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml index 64e16731..226a9749 100644 --- a/docs/cfn-template.yaml +++ b/docs/cfn-template.yaml @@ -64,5 +64,5 @@ Resources: Arn: !GetAtt Queue.Arn Outputs: QueueURL: - Description: Url used by AWS NTH controller + Description: Queue url for AWS NTH controller Value: !Ref Queue From 773e736fb8dc9eb38eec280ed6b31d82e76f6cb6 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 08:51:39 +0530 Subject: [PATCH 03/10] AWS Health Event added AWS Health Event added in CFN Template --- docs/cfn-template.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml index 226a9749..810674f9 100644 --- a/docs/cfn-template.yaml +++ b/docs/cfn-template.yaml @@ -29,6 +29,17 @@ Resources: 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: From 91a2e8ea2d187d8217e6c60d7039326fa6b5271f Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 08:59:08 +0530 Subject: [PATCH 04/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3abbce70..dd127b53 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,8 @@ The termination handler deployment requires some infrastructure to be setup befo 2. AutoScaling Group Termination Lifecycle Hook 3. Amazon EventBridge Rule 4. IAM Role for the aws-node-termination-handler Queue Processing Pods + +Cloudformation Template for creating SQS and EventBridge Rules can be found at [docs/cfn-template.yaml](docs/cfn-template.yaml) #### 1. Create an SQS Queue: From e64bac3df942112ae26c67efdba92583026d3efd Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 09:08:30 +0530 Subject: [PATCH 05/10] Spell bug fix --- docs/cfn-template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml index 810674f9..4ba5dc45 100644 --- a/docs/cfn-template.yaml +++ b/docs/cfn-template.yaml @@ -29,7 +29,7 @@ Resources: Targets: - Id: 1 Arn: !GetAtt Queue.Arn - ScheduledChangeRule: + ScheduleChangeRule: Type: 'AWS::Events::Rule' Properties: EventPattern: From 60fcf4aa048ee683ec2985387161f6def2f03fa2 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 09:18:02 +0530 Subject: [PATCH 06/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd127b53..11a64226 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ The termination handler deployment requires some infrastructure to be setup befo 3. Amazon EventBridge Rule 4. IAM Role for the aws-node-termination-handler Queue Processing Pods -Cloudformation Template for creating SQS and EventBridge Rules can be found at [docs/cfn-template.yaml](docs/cfn-template.yaml) +CloudFormation template for creating SQS and EventBridge rules can be found at [docs/cfn-template.yaml](docs/cfn-template.yaml) #### 1. Create an SQS Queue: From fdf0080ad3a6627136bc2d8574d74375f163038a Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 09:22:33 +0530 Subject: [PATCH 07/10] Update cfn-template.yaml --- docs/cfn-template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cfn-template.yaml b/docs/cfn-template.yaml index 4ba5dc45..810674f9 100644 --- a/docs/cfn-template.yaml +++ b/docs/cfn-template.yaml @@ -29,7 +29,7 @@ Resources: Targets: - Id: 1 Arn: !GetAtt Queue.Arn - ScheduleChangeRule: + ScheduledChangeRule: Type: 'AWS::Events::Rule' Properties: EventPattern: From 8b4c34d48c8daa1d54f3785f74b7de0663c034d3 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 23:27:06 +0530 Subject: [PATCH 08/10] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 11a64226..063f44b3 100644 --- a/README.md +++ b/README.md @@ -199,12 +199,10 @@ The termination handler deployment requires some infrastructure to be setup befo 2. AutoScaling Group Termination Lifecycle Hook 3. Amazon EventBridge Rule 4. IAM Role for the aws-node-termination-handler Queue Processing Pods - -CloudFormation template for creating SQS and EventBridge rules can be found at [docs/cfn-template.yaml](docs/cfn-template.yaml) #### 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 From fd4a4b85adcc31d3268ea2e2c99a9c68751a7023 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 23:28:04 +0530 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 063f44b3..603528e5 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ The termination handler deployment requires some infrastructure to be setup befo 4. IAM Role for the aws-node-termination-handler Queue Processing Pods #### 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 (template describing these resources can be found [here](docs/cfn-template.yaml)): ``` From bba0ab362a99d7be8ed7814b6b6c60737f82c76d Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Fri, 18 Mar 2022 23:41:43 +0530 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 603528e5..17a977c4 100644 --- a/README.md +++ b/README.md @@ -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 \