queirozsc
8/30/2017 - 10:44 PM

Deploying a Development Environment in Amazon EC2 Using the AWS Command Line Interface http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide

[Manipulando AWS EC2] Disponibilizando um ambiente de desenvolvimento no AWS EC2 usando a linha de comando. Fonte: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-subnets-commands-example.html #aws #awscli #ec2 #vpc #ssh

# Create a security group
aws ec2 create-security-group --group-name devenv-sg --description "security group for development environment in EC2" ;
# Create a VPN
aws ec2 create-vpc --cidr-block 10.0.0.0/16 ;
# Authorize TCP port 22 connections for security group
aws ec2 authorize-security-group-ingress --group-name devenv-sg --protocol tcp --port 22 --cidr 0.0.0.0/0 ;
# Create a subnet (note: modify the VPC id by that generated by create-vpc command)
aws ec2 create-subnet --vpc-id vpc-49390f30 --cidr-block 10.0.1.0/24 ;
# Create a certificate file for SSH connect
aws ec2 create-key-pair --key-name devenv-key --query 'KeyMaterial' --output text > devenv-key.pem ;
# Change the certificate file permissions to root only execution
chmod 400 devenv-key.pem ;
# Create the gateway
aws ec2 create-internet-gateway ;
# Attach the gateway (note: modify the VPC and gateway ids)
aws ec2 attach-internet-gateway --vpc-id vpc-49390f30 --internet-gateway-id igw-68a4b00e ;
# Run EC2 instance (note: modify the security group)
aws ec2 run-instances --image-id ami-4fffc834 --security-group-ids sg-b018ced5 --count 1 --instance-type t1.micro --key-name devenv-key --query 'Instances[0].InstanceId' ;
# Create route table for VPN (note: modify the VPC id)
aws ec2 create-route-table --vpc-id vpc-49390f30 ;
# Get public IP address (note: modify the instance id)
aws ec2 describe-instances --instance-ids "i-0787e4282810ef9cf" --query 'Reservations[0].Instances[0].PublicIpAddress' ;
# Create route for connection (note: modify route table and gateway id)
aws ec2 create-route --route-table-id rtb-0d10b276 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-68a4b00e ;
# Connect to EC2 instance (note: modify public IP address)
ssh -i devenv-key.pem ec2-user@54.183.22.255 ;
# Get subnet of EC2 instance (note: modify VPC id)
aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-49390f30" --query 'Subnets[*].{ID:SubnetId,CIDR:CidrBlock}' ;
# Associate to existing route table (note: modify the subnet and route table id)
aws ec2 associate-route-table  --subnet-id subnet-4b32c774 --route-table-id rtb-0d10b276 ;
# Create a new certificate file
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem ;
chmod 400 MyKeyPair.pem ;
# Create a security group for SSH access (note: modify the VPC id)
aws ec2 create-security-group --group-name SSHAccess --description "Security group for SSH access" --vpc-id vpc-49390f30 ;
# Authorize TCP port 22 connections for security group (note: modify the security group)
aws ec2 authorize-security-group-ingress --group-id sg-c5de90b5 --protocol tcp --port 22 --cidr 0.0.0.0/0 ;
# Connect to EC2 instance (note: modify public IP address)
ssh -i "MyKeyPair.pem" ec2-user@34.233.93.139 ;