Advertisement
Javi

AWS: create a VPC with two public subnets, an ELB and an ASG

Aug 14th, 2013
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.17 KB | None | 0 0
  1. >ec2-create-vpc "10.0.0.0/16" --region us-west-2
  2. VPC vpc-27be574c pending 10.0.0.0/16 dopt-c0bc55ab default
  3.  
  4.  
  5. >ec2-create-group web-sg --description "80, 8080, 22 (web y app server)" --vpc vpc-27be574c --region us-west-2
  6. GROUP sg-0d7f9062 web-sg 80, 8080, 22 (web y app server)
  7.  
  8. >ec2-authorize sg-0d7f9062 -P TCP -p 80 -s "0.0.0.0/0"
  9. PERMISSION ALLOWS tcp 80 80 FROM CIDR 0.0.0.0/0 ingress
  10.  
  11. >ec2-authorize sg-0d7f9062 -P TCP -p 8080 -s "0.0.0.0/0"
  12. GROUP sg-0d7f9062
  13. PERMISSION ALLOWS tcp 8080 8080 FROM CIDR 0.0.0.0/0 ingress
  14.  
  15. >ec2-authorize sg-0d7f9062 -P TCP -p 22 -s "10.0.0.0/16"
  16. GROUP sg-0d7f9062
  17. PERMISSION ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/16 ingress
  18.  
  19. >ec2-create-subnet --vpc vpc-27be574c -cidr "10.0.0.0/24" --availability-zone us-west-2a --region us-west-2
  20. SUBNET subnet-15be577e pending vpc-27be574c 10.0.0.0/24 251 us-west-2a
  21.  
  22. >ec2-create-subnet --vpc vpc-27be574c -cidr "10.0.1.0/24" --availability-zone us-west-2b --region us-west-2
  23. SUBNET subnet-e4be578f pending vpc-27be574c 10.0.1.0/24 251 us-west-2b
  24.  
  25. >ec2-describe-subnets --region us-west-2
  26. SUBNET subnet-15be577e available vpc-27be574c 10.0.0.0/24 251 us-west-2a false false
  27. SUBNET subnet-e4be578f available vpc-27be574c 10.0.1.0/24 251 us-west-2b false false
  28.  
  29.  
  30. >ec2-create-internet-gateway
  31. INTERNETGATEWAY igw-f69a739d
  32.  
  33. >ec2-attach-internet-gateway igw-f69a739d --vpc vpc-27be574c --region us-west-2
  34. ATTACHMENT vpc-27be574c attaching
  35.  
  36. >ec2-create-route-table vpc-27be574c --region us-west-2
  37. ROUTETABLE rtb-2ddb3146 vpc-27be574c
  38. ROUTE local active 10.0.0.0/16 CreateRouteTable
  39.  
  40. >ec2-create-route rtb-2ddb3146 --cidr 0.0.0.0/0 --gateway igw-f69a739d --region us-west-2
  41. ROUTE igw-f69a739d 0.0.0.0/0
  42.  
  43. >ec2-associate-route-table rtb-2ddb3146 --subnet subnet-15be577e --region us-west-2
  44. ASSOCIATION rtbassoc-a2d933c9 rtb-2ddb3146 subnet-15be577e
  45.  
  46. >ec2-associate-route-table rtb-2ddb3146 --subnet subnet-e4be578f --region us-west-2
  47. ASSOCIATION rtbassoc-8cd933e7 rtb-2ddb3146 subnet-e4be578f
  48.  
  49. >elb-create-lb web-lb --listener "protocol=http, lb-port=80, instance-port=80" --listener "protocol=http, lb-port=8080, instance-port=8080" --subnets "subnet-15be577e" --region us-west-2
  50. DNS_NAME web-lb-966134185.us-west-2.elb.amazonaws.com
  51.  
  52. >elb-describe-lbs --region us-west-2
  53. LOAD_BALANCER web-lb web-lb-966134185.us-west-2.elb.amazonaws.com 2013-08-13T14:51:19.990Z internet-facing
  54.  
  55. >elb-attach-lb-to-subnets web-lb -subnets subnet-e4be578f --region us-west-2
  56. SUBNETS subnet-15be577e, subnet-e4be578f
  57.  
  58. >elb-configure-healthcheck web-lb --target "HTTP:80/" --interval 15 --timeout 10 --unhealthy-threshold 2 --healthy-threshold 2 --region us-west-2
  59. HEALTH_CHECK HTTP:80/ 15 10 2 2
  60.  
  61. >elb-configure-healthcheck web-lb --target "HTTP:8080/" --interval 15 --timeout 10 --unhealthy-threshold 2 --healthy-threshold 2 --region us-west-2
  62. HEALTH_CHECK HTTP:8080/ 15 10 2 2
  63.  
  64. >elb-apply-security-groups-to-lb web-lb --security-groups sg-0d7f9062 --region us-west-2
  65. SECURITYGROUPS sg-0d7f9062
  66.  
  67. >as-create-launch-config webserver-lc --image-id ami-b0b52880 --group sg-0d7f9062 --instance-type m1.small --region us-west-2
  68. OK-Created launch config
  69.  
  70. >as-describe-launch-configs --region us-west-2
  71. LAUNCH-CONFIG webserver-lc ami-b0b52880 m1.small
  72.  
  73. >as-create-auto-scaling-group web-asg --min-size 1 --max-size 3 --default-cooldown 300 --grace-period 100 --health-check-type ELB --launch-configuration webserver-lc --load-balancers web-lb --vpc-zone-identifier "subnet-15be577e, subnet-e4be578f" --region us-west-2
  74. OK-Created AutoScalingGroup
  75.  
  76. >elb-describe-lbs --region us-west-2
  77. LOAD_BALANCER web-lb web-lb-966134185.us-west-2.elb.amazonaws.com 2013-08-13T14:51:19.990Z internet-facing
  78.  
  79. C:\Users\ciberado
  80. >as-describe-scaling-activities --region us-west-2
  81. No activities found
  82.  
  83. C:\Users\ciberado
  84. >as-describe-scaling-activities --region us-west-2
  85. ACTIVITY d4fd8aef-2c78-4481-9b17-a41d776477f7 web-asg PreInService
  86.  
  87. >sns-create-topic webasg-change --region us-west-2
  88. arn:aws:sns:us-west-2:562397084151:webasg-change
  89.  
  90. >sns-subscribe arn:aws:sns:us-west-2:562397084151:webasg-change --protocol email --endpoint email@company.com --region us-west-2
  91. Subscription request received.
  92.  
  93. (check email and click on the link)
  94. Your subscription's id is:
  95. arn:aws:sns:us-west-2:562397084151:webasg-change:5352f5c5-ecf8-49cc-b47a-04ab3d714027
  96.  
  97. >as-describe-auto-scaling-notification-types
  98. NOTIFICATION-TYPE autoscaling:EC2_INSTANCE_LAUNCH
  99. NOTIFICATION-TYPE autoscaling:EC2_INSTANCE_LAUNCH_ERROR
  100. NOTIFICATION-TYPE autoscaling:EC2_INSTANCE_TERMINATE
  101. NOTIFICATION-TYPE autoscaling:EC2_INSTANCE_TERMINATE_ERROR
  102. NOTIFICATION-TYPE autoscaling:TEST_NOTIFICATION
  103.  
  104. >as-put-notification-configuration web-asg --topic-arn arn:aws:sns:us-west-2:562397084151:webasg-change --notification-types autoscaling:EC2_INSTANCE_LAUNCH, autoscaling:EC2_INSTANCE_LAUNCH_ERROR, autoscaling:EC2_INSTANCE_TERMINATE, autoscaling:EC2_INSTANCE_TERMINATE_ERROR, autoscaling:TEST_NOTIFICATION --region us-west-2
  105.  
  106. >as-put-scaling-policy webup-sp --type ChangeInCapacity --adjustment=1 --cooldown=200 --auto-scaling-group web-asg --region us-west-2
  107. arn:aws:autoscaling:us-west-2:562397084151:scalingPolicy:6f0b8f13-c9e0-4509-aba0-506b89dff5dc:autoScalingGroupName/web-asg:policyName/webup-sp
  108.  
  109. >as-put-scaling-policy webdn-sp --type ChangeInCapacity "--adjustment=-1" --cooldown=200 --auto-scaling-group web-asg --region us-west-2
  110. arn:aws:autoscaling:us-west-2:562397084151:scalingPolicy:1d7dd0d0-483e-4be0-81de-186e4018cff5:autoScalingGroupName/web-asg:policyName/webdn-sp
  111.  
  112. >mon-put-metric-alarm highCPU-a --comparison-operator GreaterThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 120 --threshold 85 --alarm-actions arn:aws:autoscaling:us-west-2:562397084151:scalingPolicy:6f0b8f13-c9e0-4509-aba0-506b89dff5dc:autoScalingGroupName/web-asg:policyName/webup-sp --dimensions "AutoScalingGroupName=web-asg" -statistic Average --region us-west-2
  113. OK-Created Alarm
  114. está activado.
  115.  
  116. >mon-put-metric-alarm lowCPU-a --comparison-operator LessThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 120 --threshold 40 --alarm-actions arn:aws:autoscaling:us-west-2:562397084151:scalingPolicy:1d7dd0d0-483e-4be0-81de-186e4018cff5:autoScalingGroupName/web-asg:policyName/webdn-sp --dimensions "AutoScalingGroupName=web-asg" -statistic Average --region us-west-2
  117. OK-Created Alarm
  118. está activado.
  119.  
  120. >mon-describe-alarms --region us-west-2
  121. highCPU-a OK arn:aws:autoscalin...policyName/webup-sp AWS/EC2 CPUUtilization 120 Average 1 GreaterThanThreshold 85.0
  122. lowCPU-a ALARM arn:aws:autoscalin...policyName/webdn-sp AWS/EC2 CPUUtilization 120 Average 1 LessThanThreshold 40.0
  123. está activado.
  124.  
  125. >mon-delete-alarms HighCPU-a, LowCPU-a --region us-west-2
  126. OK-Deleted alarms
  127. está activado.
  128.  
  129. >as-delete-policy webdn-sp --auto-scaling-group web-asg --region us-west-2
  130. OK-Deleted Policy
  131.  
  132. >as-delete-policy webup-sp --auto-scaling-group web-asg --region us-west-2
  133. OK-Deleted Policy
  134.  
  135. >as-delete-notification-configuration web-asg --topic-arn arn:aws:sns:us-west-2:562397084151:webasg-change --region us-west-2
  136. OK-Deleted Notification Configuration
  137.  
  138. >sns-delete-topic arn:aws:sns:us-west-2:562397084151:webasg-change --region us-west-2
  139. Topic deleted.
  140.  
  141. >as-update-auto-scaling-group web-asg --min-size 0 --max-size 0 --desired-capcity 0 --region us-west-2
  142. OK-Updated AutoScalingGroup
  143.  
  144. >as-delete-auto-scaling-group web-asg --region us-west-2
  145. OK-Deleted AutoScalingGroup
  146.  
  147. >as-delete-launch-config webserver-lc --region us-west-2
  148. OK-Deleted launch configuration
  149.  
  150. ERRORES:
  151.  
  152. >elb-detach-lb-from-subnets web-lb --subnets "subnet-15be577e, subnet-e4be578f" --region us-west-2
  153. elb-detach-lb-from-subnets: program error
  154.  
  155. >elb-delete-lb web-lb --region us-west-2
  156. elb-delete-lb: program error
  157.  
  158. OK, after removing it with the console.
  159. (TODO: remove the rest of the created resources)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement