Skip to content

Instantly share code, notes, and snippets.

@jtomaszon
Created April 10, 2016 20:26
Show Gist options
  • Save jtomaszon/44b0952ae9e70addc58eeac7ccf25835 to your computer and use it in GitHub Desktop.
Save jtomaszon/44b0952ae9e70addc58eeac7ccf25835 to your computer and use it in GitHub Desktop.
Create your own Free-tier Infrastructure from your terminal

Install awscli

sudo -H pip install awscli --ignore-installed six

Collecting awscli [..]

Installing collected packages: pyasn1, rsa, futures, jmespath, six, python-dateutil, docutils, botocore, s3transfer, colorama, awscli Successfully installed awscli-1.10.19 botocore-1.4.10 colorama-0.3.3 docutils-0.12 futures-3.0.5 jmespath-0.9.0 pyasn1-0.1.9 python-dateutil-1.5 rsa-3.3 s3transfer-0.0.1 six-1.4.1

aws configure
AWS Access Key ID [None]: ***
AWS Secret Access Key [None]: ******
Default region name [None]: **-****-1
Default output format [None]: table

====

EC2 creation

Create your first keypair

aws ec2 create-key-pair --key-name MyKey --query 'KeyMaterial' --output text > ~/.ssh/mykey.pem
chmod 400 ~/.ssh/mykey.pem

Create a new Security group for Web access

aws ec2 create-security-group --group-name fw-kbit-web --description "Default kbit.io Firewall"

Apply new rules

aws ec2 authorize-security-group-ingress --group-name fw-kbit-web --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name fw-kbit-web --protocol tcp --port 22 --cidr 0.0.0.0/0

Create your instance

  • Ubuntu: ami-0fb83963
  • Free-tier Instance: t2.micro
aws ec2 run-instances --image-id ami-0fb83963 --count 1 --instance-type t2.micro --key-name MyKey --security-groups fw-kbit-web 

Save important information from the output

KEY VALUE
InstanceId i-0ffac8ea9f6ea0619
InstanceType t2.micro

NetworkInterface

  • Description
  • MacAddress
  • NetworkInterfaceId
  • OwnerId
  • PrivateDnsName
  • PrivateIpAddress
  • SourceDestCheck
  • Status
  • SubnetId
  • VpcId

Attach a bigger partition for future usage

aws ec2 create-volume --size 20 --region sa-east-1 --availability-zone sa-east-1a --volume-type gp2

Use the volumeId to attach it to the right Instance

aws ec2 attach-volume --volume-id vol-5b4f77fa --instance-id i-0ffac8ea9f6ea0619 --device /dev/sdf

Allocate an ElasticIP

aws ec2 allocate-address --domain standard

Associate it with your instance

aws ec2 associate-address --instance-id i-0ffac8ea9f6ea0619 --public-ip ##.###.##.##

Be heroe!

ssh -i .ssh/mykey.pem ubuntu@##.###.##.##
ubuntu@ip-###-##-##-###:~$

====

S3 Bucket

Create a bucket

aws s3api create-bucket --bucket bucketName --region sa-east-1

If the bucket name already exists, you will receive an error like

A client error (BucketAlreadyExists) occurred when calling the CreateBucket operation: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

So try again :)

aws s3api create-bucket --bucket randomNameToAvoidDuplicates --region sa-east-1

====

RDS MySQL Instance

Create your Security Group

aws ec2 create-security-group --group-name fw-kbit-db --description "Default kbit.io Firewall DB"

Allow your instance to connect to the DB node

Change internalIP for your Private ElasticIP

aws ec2 authorize-security-group-ingress --group-name fw-kbit-db --protocol tcp --port 3306 --cidr ##internalIP##

Create your instance

Change the Identifier to match your application name

Change master-username and master-user-password

  • Free-tier: db.t2.micro
  • Free-tire: 20GB
  • Define your Security Group
  • Disable MultiAZ
aws rds create-db-instance --db-instance-identifier ##Identifier## --allocated-storage 20 --db-instance-class db.t2.micro --engine mysql --master-username ##USER## --master-user-password ##PASSWORD## --availability-zone sa-east-1a --vpc-security-group-ids sg-2b1c154e --storage-type gp2 --no-multi-az

Create a .my.cnf with the proper configuration

[client]
host=##identifier##.rds.host
user=##USER##
password=##PASSWORD##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment