Monday, May 30, 2016

AWs basics: S3

Local Setup

  • npm install aws-sdk
  • create a .aws/credentails file in the ${user_home} directory ( True for both MAC, LInux and Windows )
  • Copy the below contents to the ${user_home}/.aws/credentials file:
AWSAccessKeyId=agahaha
AWSSecretKey=ahahahae

Also create .aws/config file and add the following two lines:
[default]
region = us-west-2
How to work with pre-signed URLs
Bucket name: my.test
Region: us-west-2
Content Folder: mycontent
I have tested the above by creating pre-signed URLs for upload content:
My logs:

Public and Private Folder for Content on S3

  1. Log into the AWS console
  2. Browse to my.test/content/public folder
  3. Right click and choose 'public'.
  4. Well that makes it all public.
Set CORS at AWS


AWS basics: EC2


Note: Draft document, needs review.

Ec2 instance Username and password to connect to AWS console:



PW: boomboom


Ec2 instance type : m4.large instance with 2 vCPU and 8GiB memory.

Availability Zone: Oregon

Elastic IP :  a.b.c.d


Instance name : alpha-z

Instance ID is :  i-1884a1c0)

Private IP is : k.n.m.z

EC2 instance image :  Amazon Linux AMI 2016.03.0 x86_64 HVM GP2

Opened port: Port # 22 (ssh) and 3000 (nodeJS)




UsersRoot - root (Super user creds are unknown.Need to check in the image document)
Main user : ec2-user


MongoDB  Version  - MongoDB 3.2

MongoDB is running on port 27017

MongoDB can be connected via browser using url - http://a.b.c.d:27017/ (Currently port 27017 is blocked for any incoming call from external IP. Only app server running on localhost can access it)

MongoDB service starts automatically when instance is booted

MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb by default.

Config file of mongoDB “mongod.config” lies on /etc.

All mongo executable in /usr/bin folder.

stop mongoDB service using command  - “sudo service mongod stop”

start mongoDB service using command “sudo service mongod start”




Conect to MongoMongo port 27017 is blocked for all external access. Change /etc/mongod.conf bind_id and inboudn/outbound of aws console security group.
But one can connect to mongo shell after login to the ec2 instance.
Strange: localhost, a.b.c.d and ec2-.... public DNS does not work. Only thing that works is :
sudo mongo 127.0.0.1:27017/mydb -u my-admin -p admin-pwd

Incase of error 'BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly'
Run the command > export LC_ALL=C






Node JS installation version v6.0.0-pre

Installation directory : /home/ec2-user/node


NodeJS service does not start when instance is started. Need to work on that.





Node JS Application serverWebserver location - /opt/myserver

NodeJS app server port : 3000

URL to connect the server: http://a.b.c.d:3000/






Ec2 instance connection with putty (Windows)
  • Open Puttygen and load the private key (.pem file). This file can be downloaded from AWS. Then save the private key (.ppk file) on your disk
  • Then open putty, and load this private (.ppk file) in  SSH->AUTH section.
  • Then connect to instance with host as ec2-user@ipaddress
  • Now you will be remotely access the EC2 instance.




Ec2 instance connection ssh client ( Mac or Linux )
  • Get the private key (.pem or ppk ) file from the admin. Contact the admin.
  • Store it at your local machine, at a secure path, say, /path/my-private-key.pem
  • Change permissions of the my-private-key.pem file: chmod 400 /path/my-private-key.pem
  • command to connect: ssh -i /path/my-private-key.pem {user}@{public_dns}
    common user: ec2-user
    public dns for the ec2 instance: ec2-a-b-c-d.us-west-2.compute.amazonaws.com

     




Setup Git repoCommands below :
  • cd /opt
  • sudo mkdir "myserver"
  • cd /opt/myserver/
  • sudo git init
  • sudo git clone https:///myrepo.git