{"id":7497,"date":"2018-06-01T15:10:43","date_gmt":"2018-06-01T07:10:43","guid":{"rendered":"http:\/\/rmohan.com\/?p=7497"},"modified":"2018-06-01T15:10:43","modified_gmt":"2018-06-01T07:10:43","slug":"aws-cli-part-1","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7497","title":{"rendered":"aws cli part -1"},"content":{"rendered":"<p>1. Create a VPC<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.0.0.0\/16<\/p>\n<p>2. Create a VPC with dedicated tenancy<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.0.0.0\/16 &#8211;instance-tenancy dedicated<\/p>\n<p>3. Create a VPC with an IPv6 CIDR block<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.16.0.0\/16 &#8211;amazon-provided-ipv6-cidr-block &gt;&gt; \/root\/awscreateVPC.json<\/p>\n<p>4. Create a subnet within the VPC<\/p>\n<p>aws ec2 create-subnet &#8211;vpc-id\u00a0 vpc-b774aace &#8211;cidr-block 10.16.1.0\/24\u00a0 &gt;&gt; \/root\/awscreateSubnet1.json<\/p>\n<p>aws ec2 create-subnet &#8211;vpc-id\u00a0 &#8220;vpc-b774aace&#8221; &#8211;cidr-block &#8220;10.16.2.0\/24&#8221;\u00a0 &#8211;availability-zone\u00a0 &#8220;us-east-1a&#8221; &gt;&gt; \/root\/awscreateSubnet2.json<\/p>\n<p>6. Delete VPC<\/p>\n<p>aws ec2 delete-vpc\u00a0 &#8211;vpc-id vpc-7c6ab405<\/p>\n<p>7. Create route table (a default route table is created during vpc creation)<\/p>\n<p>aws ec2 create-route-table &#8211;vpc-id vpc-b774aace\u00a0 &gt;&gt;\u00a0 \/root\/awscreateRouteTable.json<\/p>\n<p>8. Associate subnet (say our subnet2 id = subnet-2b8a2c07) with the above route table (say route table id = rtb-0068f078)<\/p>\n<p>aws ec2 associate-route-table &#8211;route-table-id\u00a0 rtb-0068f078 &#8211;subnet-id subnet-2b8a2c07 &gt;&gt;\u00a0 \/root\/awsassociateRouteTable.json<\/p>\n<p>9. Dissociate subnet from route table<\/p>\n<p>aws ec2 disassociate-route-table &#8211;association-id rtbassoc-802b6efb<\/p>\n<p>10. Create Internet Gateway<\/p>\n<p>aws ec2 create-internet-gateway &gt;&gt; \/root\/awscreateInternetGateway.json<\/p>\n<p>11. Attach Internet Gateway to VPC (An Internet gateway already attached to an vpc cannot be attached to another vpc)<\/p>\n<p>aws ec2 attach-internet-gateway &#8211;internet-gateway-id\u00a0\u00a0 igw-b946d3df\u00a0\u00a0 &#8211;vpc-id vpc-b774aace &gt;&gt; \/root\/awsattachInternetGateway.json<\/p>\n<p>12. Detach Internet Gateway<\/p>\n<p>aws ec2 detach-internet-gateway\u00a0\u00a0\u00a0\u00a0 &#8211;internet-gateway-id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 igw-b946d3df\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;vpc-id\u00a0 vpc-b774aace<\/p>\n<p>13.\u00a0 Create Route\u00a0\u00a0 (To create new route you need a Internet Gateway, Network Interface, or Virtual Private Gateway as targets.)<\/p>\n<p>aws ec2 create-route &#8211;route-table-id\u00a0 rtb-714cd209 &#8211;destination-cidr-block 0.0.0.0\/0 &#8211;gateway-id igw-b946d3df<\/p>\n<p>14. Create NACL<\/p>\n<p>aws ec2\u00a0 create-network-acl\u00a0 &#8211;vpc-id vpc-b774aace &gt;&gt; \/root\/awscreateNetworkACL.json<\/p>\n<p>15. Create NACL entry (to add a allow or deny rule)<\/p>\n<p>aws ec2 create-network-acl-entry &#8211;network-acl-id\u00a0\u00a0\u00a0 acl-f769128e\u00a0\u00a0 &#8211;ingress\u00a0 &#8211;rule-number 25 &#8211;protocol tcp &#8211;port-range From=22,To=22&#8211;cidr-block 0.0.0.0\/0\u00a0 &#8211;rule-action allow<\/p>\n<p>aws ec2 create-network-acl-entry &#8211;network-acl-id\u00a0\u00a0\u00a0 acl-f769128e\u00a0\u00a0 &#8211;ingress\u00a0 &#8211;rule-number 35 &#8211;protocol tcp &#8211;port-range From=80,To=80&#8211;cidr-block 0.0.0.0\/0\u00a0 &#8211;rule-action allow<\/p>\n<p>aws ec2 create-network-acl-entry &#8211;network-acl-id\u00a0\u00a0\u00a0 acl-f769128e\u00a0\u00a0 &#8211;ingress\u00a0 &#8211;rule-number 50 &#8211;protocol all &#8211;port-range From=0,To=65535 &#8211;cidr-block 10.16.2.251\/32 &#8211;rule-action deny<\/p>\n<p>aws ec2 create-network-acl-entry &#8211;network-acl-id\u00a0\u00a0\u00a0 acl-f769128e\u00a0\u00a0 &#8211;exgress\u00a0 &#8211;rule-number 50 &#8211;protocol all &#8211;port-range From=0,To=65535 &#8211;cidr-block 10.16.2.251\/32 &#8211;rule-action deny<\/p>\n<p>16. Modify NACL Entry<\/p>\n<p>aws ec2 replace-network-acl-entry &#8211;network-acl-id\u00a0\u00a0\u00a0 acl-f769128e\u00a0\u00a0 &#8211;ingress\u00a0 &#8211;rule-number 100 &#8211;protocol all &#8211;port-range From=0,To=65535 &#8211;cidr-block 10.16.2.0\/24 &#8211;rule-action allow<\/p>\n<p>17. create security group<\/p>\n<p>aws ec2 create-security-group &#8211;group-name mySG1 &#8211;description &#8220;my security group&#8221; &#8211;vpc-id vpc-b774aace<\/p>\n<p>18. Create SG inbound (To add a rule that allows inbound SSH traffic)<\/p>\n<p>aws ec2 authorize-security-group-ingress &#8211;group-id sg-3fdcc241 &#8211;protocol tcp &#8211;port 22 &#8211;cidr 0.0.0.0\/0<\/p>\n<p>19. Create SG inbound (To add a rule that allows inbound HTTP traffic from another security group)<\/p>\n<p>aws ec2 authorize-security-group-ingress &#8211;group-id sg-3fdcc241 &#8211;protocol tcp &#8211;port 80 &#8211;cidr 0.0.0.0\/0<\/p>\n<p>Note: for https use port 443<\/p>\n<p>20. Create key pair<\/p>\n<p>aws ec2 create-key-pair &#8211;key-name MyKeyPair &#8211;query &#8216;KeyMaterial&#8217; &#8211;output text &gt;&gt; \/root\/awsMyKeyPair.pem<\/p>\n<p>aws ec2 create-key-pair &#8211;key-name MyKeyPair &#8211;query &#8216;KeyMaterial&#8217; &#8211;output text | out-file -encoding ascii -filepath MyKeyPair.pem\u00a0 [windows powershell]<\/p>\n<p>21. Launches the specified number of instances using an AMI for which you have permissions.<\/p>\n<p>aws ec2 run-instances<\/p>\n<p>15. Delete route table<\/p>\n<p>aws ec2\u00a0 delete-route-table &#8211;route-table-id\u00a0\u00a0\u00a0 rtb-4069f138<\/p>\n<p>9. aws ec2 associate-route-table &#8211;route-table-id rtb-22574640 &#8211;subnet-id subnet-9d4a7b6c<br \/>\n4. To create an endpoint<\/p>\n<p>aws ec2 create-vpc-endpoint &#8211;vpc-id vpc-1a2b3c4d &#8211;service-name com.amazonaws.us-east-1.s3 &#8211;route-table-ids rtb-11aa22bb<\/p>\n<p>This example creates a VPC endpoint between VPC vpc-1a2b3c4d and Amazon S3 in the us-east-1 region, and associates route table rtb-11aa22bb with the endpoint.<\/p>\n<p>5. To create a VPC peering connection between your VPCs<\/p>\n<p>aws ec2 create-vpc-peering-connection &#8211;vpc-id vpc-1a2b3c4d &#8211;peer-vpc-id vpc-11122233<\/p>\n<p>6. To create a VPC peering connection with a VPC in another account<\/p>\n<p>aws ec2 create-vpc-peering-connection &#8211;vpc-id vpc-1a2b3c4d &#8211;peer-vpc-id vpc-11122233 &#8211;peer-owner-id 123456789012<\/p>\n<p>7. To create a VPN connection with dynamic routing<\/p>\n<p>aws ec2 create-vpn-connection &#8211;type ipsec.1 &#8211;customer-gateway-id cgw-0e11f167 &#8211;vpn-gateway-id vgw-9a4cacf3<\/p>\n<p>8. To create a static route for a VPN connection<\/p>\n<p>aws ec2 create-vpn-connection-route &#8211;vpn-connection-id vpn-40f41529 &#8211;destination-cidr-block 11.12.0.0\/16<\/p>\n<p>9. To create a virtual private gateway<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Create a VPC<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.0.0.0\/16<\/p>\n<p>2. Create a VPC with dedicated tenancy<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.0.0.0\/16 &#8211;instance-tenancy dedicated<\/p>\n<p>3. Create a VPC with an IPv6 CIDR block<\/p>\n<p>aws ec2 create-vpc &#8211;cidr-block 10.16.0.0\/16 &#8211;amazon-provided-ipv6-cidr-block &gt;&gt; \/root\/awscreateVPC.json<\/p>\n<p>4. Create a subnet within the VPC<\/p>\n<p>aws ec2 create-subnet &#8211;vpc-id vpc-b774aace &#8211;cidr-block 10.16.1.0\/24 &gt;&gt; [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7497"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7497"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7497\/revisions"}],"predecessor-version":[{"id":7498,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7497\/revisions\/7498"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}