Skip to content

Commit

Permalink
Create rollingUpdate.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanth979 committed Oct 18, 2020
1 parent b036100 commit 5bb2df3
Showing 1 changed file with 214 additions and 0 deletions.
214 changes: 214 additions & 0 deletions rollingUpdate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
AWSTemplateFormatVersion: '2010-09-09'
Resources:
ELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
GroupName: ELBSecurityGroup
VpcId:
Ref: MyVPCId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
GroupName: AppInstanceSecurityGroup
VpcId:
Ref: MyVPCId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
DependsOn:
- ELBSecurityGroup
ELB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name:
Ref: InternalELBName
Scheme: internet-facing
SecurityGroups: [
Ref: ELBSecurityGroup ]
Subnets:
Ref: Subnets
Type: application
ELBTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 10
HealthCheckPath: "/"
HealthCheckPort: '80'
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 5
Matcher:
HttpCode: '200'
Name: APP
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
UnhealthyThresholdCount: 2
VpcId:
Ref: MyVPCId
DependsOn:
- ELB
ELBDefaultListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn:
Ref: ELB
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ELBTargetGroup
Port: 80
Protocol: HTTP
DependsOn:
- ELB
- ELBTargetGroup
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MaxSize:
Ref: ASGMaxSize
MinSize:
Ref: ASGMinSize
DesiredCapacity:
Ref: ASGSize
HealthCheckType: ELB
HealthCheckGracePeriod: 120
LaunchConfigurationName:
Ref: LaunchConfiguration
VPCZoneIdentifier:
Ref: Subnets
TargetGroupARNs: [
Ref: ELBTargetGroup ]
TerminationPolicies:
- Default
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT10M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: '1'
MinInstancesInService: '1'
PauseTime: PT10M
SuspendProcesses:
- AlarmNotification
WaitOnResourceSignals: true
Tags:
- PropagateAtLaunch: true
Value: AppServer
Key: Purpose
DependsOn:
- LaunchConfiguration
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
AssociatePublicIpAddress: true
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
DeleteOnTermination: true
VolumeSize: 8
VolumeType: gp2
EbsOptimized: false
ImageId:
Fn::FindInMap:
- RegionMap
- Ref: AWS::Region
- AMI
InstanceMonitoring: true
InstanceType:
Ref: InstanceType
KeyName:
Ref: KeyName
SecurityGroups: [
Ref: InstanceSecurityGroup ]
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd.service
systemctl enable httpd.service
echo "<h1>Hello World welcome to App deployed using rolling update</h1>" > /var/www/html/index.html
DependsOn:
- InstanceSecurityGroup

Parameters:
MyVPCId:
Description: VPC Id
Type: AWS::EC2::VPC::Id
Subnets:
Description: List of subnets
Type: List<AWS::EC2::Subnet::Id>
InternalELBName:
Description: Internal ELB Name Assigned
Type: String
Default: my-internal-elb
ASGSize:
Description: Desired number of EC2 instances in Auto Scaling Group
Type: Number
Default: 2
ASGMinSize:
Description: Min number of EC2 instances in Auto Scaling Group
Type: Number
Default: 1
ASGMaxSize:
Description: Max number of EC2 instances in Auto Scaling Group
Type: Number
Default: 4
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t1.micro
- t2.micro
KeyName:
Description: EC2 key pair
Type: String
Default: my_ec2_key
VersionParameter:
Description: Software version to deploy
Type: String

Mappings:
RegionMap:
us-east-1:
AMI: ami-098f16afa9edf40be

Outputs:
ELB:
Value:
Fn::Join:
- ''
- - http://
- Fn::GetAtt:
- ELB
- DNSName
Description: Load Balancer URL

0 comments on commit 5bb2df3

Please sign in to comment.