Last active
November 22, 2016 05:43
-
-
Save newlyregistered26/9a2f16ede09e899d13fa8bd193b33e9c to your computer and use it in GitHub Desktop.
aws_elbv2_create
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
#Creates the target group, note the target group ARN as we'll need it several times. | |
aws elbv2 create-target-group --name sometargetgroup --protocol HTTPS --port 443 --vpc-id vpc-123456 | |
#Creates the Load Balancer - This takes some time to provision the load balancer, during this time it will in state provisioning, note the ALB ARN, as we'll need it later | |
#Create a security group to associate with the ELB | |
aws elbv2 create-load-balancer --name someALBname --subnets subnet-12345456 subnet-6543263--scheme internal --security-groups sg-12345456 | |
#Create the listener and associate the certificate registered | |
aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:loadbalancer/app/someALBname/75422c5724af4c03 --protocol HTTPS --port 443 --certificates CertificateArn=arn:aws:iam::someaccountno:server-certificate/site.example.com --ssl-policy ELBSecurityPolicy-2015-05 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:targetgroup/sometargetgroup/c72b378a052b6b4d | |
#Describes the health of the specified targets or all of your targets. Ensure that the instances are running, else you may get the following, "An error occurred (InvalidTarget) when calling the RegisterTargets operation: The following targets are not in a running state and cannot be registered: 'i-1234567'" | |
aws elbv2 describe-target-health --targets Id=i-98765432 Id=i-1234567,Port=443 --target-group-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:targetgroup/sometargetgroup/c72b378a052b6b4d | |
#Registers the specified targets with the specified target group. | |
aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:targetgroup/sometargetgroup/c72b378a052b6b4d --targets Id=i-98765432 Id=i-1234567 | |
#I noted that if one of the hosts wasn't switched on, then the registration of all nodes failed. | |
#Change LB to sticky sessions and configure for 31 minutes | |
aws elbv2 modify-target-group-attributes --target-group-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:targetgroup/sometargetgroup/c72b378a052b6b4d --attributes Key=stickiness.type,Value=lb_cookie Key=stickiness.enabled,Value=true Key=stickiness.lb_cookie.duration_seconds,Value=1860 | |
#Change LB idle timeout to 31 minutes | |
aws elbv2 modify-load-balancer-attributes --load-balancer-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:loadbalancer/app/someALBname/75422c5724af4c03 --attributes Key=idle_timeout.timeout_seconds,Value=1865 | |
#Configure Health check for /someurl/status Assumes server 200 (adjust if you have authentication) | |
aws elbv2 modify-target-group --target-group-arn arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:targetgroup/sometargetgroup/c72b378a052b6b4d --health-check-protocol HTTPS --health-check-port 443 --health-check-path /someurl/status | |
#Don't forget to tag it | |
aws elbv2 add-tags --resource-arns arn:aws:elasticloadbalancing:ap-southeast-2:someaccountno:loadbalancer/app/someALBname/75422c5724af4c03 --tags "Key=AppName,Value=SomeApp" "Key=AppID,Value=A123" "Key=Environment,Value=Production" "Key=ReleaseID,Value=3.5" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment