Advertisement
Javi

AWS: Create VPC cli tools

Feb 25th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. Creating VPC + 1 public subnet + 2 private subnet using CLI tools
  2. =================================================================
  3.  
  4.  
  5. set comando=aws ec2 create-vpc --cidr-block 10.50.0.0/16 --query Vpc.VpcId
  6. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET vpc=%F
  7.  
  8. aws ec2 create-tags --resources %vpc% --tags Key=Name,Value=cntgvpc
  9. aws ec2 create-tags --resources %vpc% --tags Key=Proyecto,Value=cntg
  10.  
  11.  
  12. set comando=aws ec2 create-subnet --vpc-id %vpc% --availability-zone us-west-2a --cidr-block 10.50.0.0/24 --query Subnet.SubnetId
  13. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET subnetPrivA=%F
  14. aws ec2 create-tags --resources %subnetPrivA% --tags Key=Name,Value=subnetPrivA
  15. aws ec2 create-tags --resources %subnetPrivA% --tags Key=Proyecto,Value=cntg
  16.  
  17. set comando=aws ec2 create-subnet --vpc-id %vpc% --availability-zone us-west-2b --cidr-block 10.50.1.0/24 --query Subnet.SubnetId
  18. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET subnetPrivB=%F
  19. aws ec2 create-tags --resources %subnetPrivB% --tags Key=Name,Value=subnetPrivB
  20. aws ec2 create-tags --resources %subnetPrivB% --tags Key=Proyecto,Value=cntg
  21.  
  22. set comando=aws ec2 create-subnet --vpc-id %vpc% --availability-zone us-west-2a --cidr-block 10.50.2.0/24 --query Subnet.SubnetId
  23. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET subnetPubA=%F
  24. aws ec2 create-tags --resources %subnetPubA% --tags Key=Name,Value=subnetPubA
  25. aws ec2 create-tags --resources %subnetPubA% --tags Key=Proyecto,Value=cntg
  26.  
  27.  
  28. set comando=aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId
  29. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET igw=%F
  30. aws ec2 create-tags --resources %igw% --tags Key=Name,Value=igw
  31. aws ec2 create-tags --resources %igw% --tags Key=Proyecto,Value=cntg
  32. aws ec2 attach-internet-gateway --internet-gateway-id %igw% --vpc-id %vpc%
  33.  
  34. set comando=aws ec2 create-route-table --vpc-id %vpc% --query RouteTable.RouteTableId
  35. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET rtPub=%F
  36. aws ec2 create-tags --resources %rtPub% --tags Key=Name,Value=rtPub
  37. aws ec2 create-tags --resources %rtPub% --tags Key=Proyecto,Value=cntg
  38. aws ec2 create-route --route-table-id %rtPub% --destination-cidr-block "0.0.0.0/0" --gateway-id %igw%
  39.  
  40. set comando=aws ec2 associate-route-table --subnet-id %subnetPubA% --route-table-id %rtPub% --query AssociationId
  41. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET assRtPub=%F
  42.  
  43. set comando=aws ec2 allocate-address --domain vpc --query AllocationId
  44. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET natEip=%F
  45.  
  46. set comando=aws ec2 create-nat-gateway --subnet-id %subnetPubA% --allocation-id %natEip% --query NatGateway.NatGatewayId
  47. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET natgw=%F
  48.  
  49.  
  50. set comando=aws ec2 create-route-table --vpc-id %vpc% --query RouteTable.RouteTableId
  51. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET rtPriv=%F
  52. aws ec2 create-tags --resources %rtPriv% --tags Key=Name,Value=rtPriv
  53. aws ec2 create-tags --resources %rtPriv% --tags Key=Proyecto,Value=cntg
  54. aws ec2 create-route --route-table-id %rtPriv% --destination-cidr-block "0.0.0.0/0" --nat-gateway-id %natgw%
  55.  
  56. set comando=aws ec2 associate-route-table --subnet-id %subnetPrivA% --route-table-id %rtPriv% --query AssociationId
  57. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET assRtPrivA=%F
  58. set comando=aws ec2 associate-route-table --subnet-id %subnetPrivB% --route-table-id %rtPriv% --query AssociationId
  59. FOR /F "tokens=* USEBACKQ" %F IN (`%comando%`) DO SET assRtPrivB=%F
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement