Skip to content

Commit

Permalink
Merge pull request #26 from prafulmehrotra/master
Browse files Browse the repository at this point in the history
Added LB latency alarm
  • Loading branch information
rnzsgh authored Mar 21, 2018
2 parents f6e71d4 + facf048 commit c5470d0
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The **_fargate.cfn.yml_** template creates:
- A CodeBuild service role
- An [Elastic Container Registry (ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html) repository
- An [Application Load Balancer (ALB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)
- A CloudWatch Alarm for ALB latency
- An [ALB Route 53 record](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-elb-load-balancer.html)
- ELB target groups stuff
- A [Fargate task definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-task-definition.html)
Expand Down
71 changes: 71 additions & 0 deletions templates/fargate.cfn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@ Parameters:
- prod
ConstraintDescription: Specify either dev or prod

LoadBalancerAlarmEvaluationPeriods:
Description: The number of periods over which data is compared to the specified threshold
Type: Number
Default: 2
MinValue: 2
ConstraintDescription: Must be at least two

LoadBalancerAlarmEvaluationPeriodSeconds:
Description: The time over which the specified statistic is applied. Specify time in seconds, in multiples of 60.
Type: Number
Default: 300
MinValue: 60
ConstraintDescription: Must be at least 60 seconds

LoadBalancerLatencySeconds:
Description: LoadBalancer latency threshold, in seconds
Type: Number
Default: 1
MinValue: 1
ConstraintDescription: Must be atleast one

EnableLBAlarm:
Description: Set to true to enable load balancer latency alarm
Type: String
ConstraintDescription: Value must be true or false
Default: false
AllowedValues:
- true
- false

Conditions:

IsTlsEnabled: !Not [ !Equals [ !Ref SSLCertificateArn, "" ] ]
Expand All @@ -187,6 +217,8 @@ Conditions:
- !Not [ !Equals [ !Ref LoadBalancerDomainName, "" ] ]
- !Not [ !Equals [ !Ref HostedZoneName, "" ] ]

IsLBAlarmEnabled: !Equals [ !Ref EnableLBAlarm, true ]

Resources:

DefaultContainerBucket:
Expand Down Expand Up @@ -715,6 +747,33 @@ Resources:
- DefaultTargetGroup
- ApplicationLoadBalancer

LBLatency:
Type: AWS::CloudWatch::Alarm
Condition: IsLBAlarmEnabled
Properties:
AlarmName: LoadBalancer Latency Alarm
AlarmDescription: !Sub LB latency is over ${LoadBalancerLatencySeconds} for ${LoadBalancerAlarmEvaluationPeriods} period(s) of ${LoadBalancerAlarmEvaluationPeriodSeconds} seconds
TreatMissingData: notBreaching
AlarmActions:
- !Ref LoadBalancerAlarmTopic
Namespace: AWS/ApplicationELB
MetricName: TargetResponseTime
ComparisonOperator: GreaterThanOrEqualToThreshold
Unit: Seconds
Statistic: Average
EvaluationPeriods: !Ref LoadBalancerAlarmEvaluationPeriods
Period: !Ref LoadBalancerAlarmEvaluationPeriodSeconds
Threshold: !Ref LoadBalancerLatencySeconds
Dimensions:
- Name: LoadBalancer
Value: !GetAtt ApplicationLoadBalancer.LoadBalancerFullName
DependsOn: ApplicationLoadBalancer

LoadBalancerAlarmTopic:
Type: AWS::SNS::Topic
Condition: IsLBAlarmEnabled
Properties:
DisplayName: LoadBalancer Alarm Topic

Outputs:

Expand Down Expand Up @@ -774,3 +833,15 @@ Outputs:
Export:
Name: !Sub ${AWS::StackName}-ApplicationLoadBalancerName

LoadBalancerAlarmTopicArn:
Description: LoadBalancer Alarm Topic ARN
Value: !Ref LoadBalancerAlarmTopic
Export:
Name: !Sub ${AWS::StackName}-LoadBalancerAlarmTopicArn

LoadBalancerAlarmTopicName:
Description: LoadBalancer Alarm Topic Name
Value: !GetAtt LoadBalancerAlarmTopic.TopicName
Export:
Name: !Sub ${AWS::StackName}-LoadBalancerAlarmTopicName

47 changes: 46 additions & 1 deletion vpc-bastion-fargate-rds.cfn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ Parameters:
AllowedPattern: "(^$|^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$)" # Allow for a blank or a domain name
ConstraintDescription: Please enter a valid domain name

LoadBalancerAlarmEvaluationPeriods:
Description: The number of periods over which data is compared to the threshold
Type: Number
Default: 2
MinValue: 2
ConstraintDescription: Must be at least one

LoadBalancerAlarmEvaluationPeriodSeconds:
Description: The time over which the specified statistic is applied. Specify time in seconds, in multiples of 60
Type: Number
Default: 300
MinValue: 60
ConstraintDescription: Must be at least 60 seconds

LoadBalancerLatencySeconds:
Description: LoadBalancer latency threshold, in seconds
Type: Number
Default: 1
MinValue: 1
ConstraintDescription: Must be atleast one

EnableLBAlarm:
Description: Set to true to enable load balancer latency alarm
Type: String
ConstraintDescription: Value must be true or false
Default: false
AllowedValues:
- true
- false

AppProtocol:
Type: String
Description: The application server protocol
Expand Down Expand Up @@ -422,6 +452,10 @@ Metadata:
- HostedZoneName
- LoadBalancerDomainName
- SSLCertificateArn
- EnableLBAlarm
- LoadBalancerLatencySeconds
- LoadBalancerAlarmEvaluationPeriodSeconds
- LoadBalancerAlarmEvaluationPeriods
- Label:
default: Initial Service CI/CD
Parameters:
Expand Down Expand Up @@ -529,7 +563,14 @@ Metadata:
default: Max Swap Use
DatabaseEnableAlarms:
default: Enable Alarms

EnableLBAlarm:
default: Enable LB Alarm
LoadBalancerAlarmEvaluationPeriods:
default: LB Alarm Periods
LoadBalancerAlarmEvaluationPeriodSeconds:
default: LB Alarm Seconds
LoadBalancerLatencySeconds:
default: LB Latency Threshold

Conditions:

Expand Down Expand Up @@ -641,6 +682,10 @@ Resources:
MaxTaggedContainerImagesToRetain: !Ref MaxTaggedContainerImagesToRetain
DaysToRetainUntaggedContainerImages: !Ref DaysToRetainUntaggedContainerImages
EnvironmentName: !Ref EnvironmentName
EnableLBAlarm: !Ref EnableLBAlarm
LoadBalancerLatencySeconds: !Ref LoadBalancerLatencySeconds
LoadBalancerAlarmEvaluationPeriodSeconds: !Ref LoadBalancerAlarmEvaluationPeriodSeconds
LoadBalancerAlarmEvaluationPeriods: !Ref LoadBalancerAlarmEvaluationPeriods

Outputs:

Expand Down
46 changes: 46 additions & 0 deletions vpc-bastion-fargate.cfn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,35 @@ Parameters:
- prod
ConstraintDescription: Specify either dev or prod

LoadBalancerAlarmEvaluationPeriods:
Description: The number of periods over which data is compared to the threshold
Type: Number
Default: 2
MinValue: 2
ConstraintDescription: Must be at least one

LoadBalancerAlarmEvaluationPeriodSeconds:
Description: The time over which the specified statistic is applied. Specify time in seconds, in multiples of 60
Type: Number
Default: 300
MinValue: 60
ConstraintDescription: Must be at least 60 seconds

LoadBalancerLatencySeconds:
Description: LoadBalancer latency threshold, in seconds
Type: Number
Default: 1
MinValue: 1
ConstraintDescription: Must be at least one

EnableLBAlarm:
Description: Set to true to enable load balancer latency alarm
Type: String
ConstraintDescription: Value must be true or false
Default: false
AllowedValues:
- true
- false

Metadata:
AWS::CloudFormation::Interface:
Expand Down Expand Up @@ -251,6 +280,10 @@ Metadata:
- HostedZoneName
- LoadBalancerDomainName
- SSLCertificateArn
- EnableLBAlarm
- LoadBalancerLatencySeconds
- LoadBalancerAlarmEvaluationPeriodSeconds
- LoadBalancerAlarmEvaluationPeriods
- Label:
default: Initial Service CI/CD
Parameters:
Expand Down Expand Up @@ -326,6 +359,15 @@ Metadata:
default: Initial Image
CodeBuildDockerImage:
default: CodeBuild Image
EnableLBAlarm:
default: Enable LB Alarm
LoadBalancerAlarmEvaluationPeriods:
default: LB Alarm Periods
LoadBalancerAlarmEvaluationPeriodSeconds:
default: LB Alarm Seconds
LoadBalancerLatencySeconds:
default: LB Latency Threshold



Conditions:
Expand Down Expand Up @@ -385,6 +427,10 @@ Resources:
MaxTaggedContainerImagesToRetain: !Ref MaxTaggedContainerImagesToRetain
DaysToRetainUntaggedContainerImages: !Ref DaysToRetainUntaggedContainerImages
EnvironmentName: !Ref EnvironmentName
EnableLBAlarm: !Ref EnableLBAlarm
LoadBalancerLatencySeconds: !Ref LoadBalancerLatencySeconds
LoadBalancerAlarmEvaluationPeriodSeconds: !Ref LoadBalancerAlarmEvaluationPeriodSeconds
LoadBalancerAlarmEvaluationPeriods: !Ref LoadBalancerAlarmEvaluationPeriods
DependsOn: VpcStack


Expand Down

0 comments on commit c5470d0

Please sign in to comment.