Monday, July 21, 2014

Launching EC2 instances - Amazon Web Services (AWS)

I hope this article will help some you who is still under the impression that AWS allows you to launch any no of instances on any region instantly.

I had the same misunderstanding till today, and learnt that you need to request them before hand to increase your quota on no of instances you can launch within a region.

First, you should read this page. It allows you to get an idea about all soft limitations on AWS services( please note that all these ec2 limitations can be revised apon your request)
http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_ec2 

You can also read about it from the EC2 FAQ page as well.
http://aws.amazon.com/ec2/faqs/#How_many_instances_can_I_run_in_Amazon_EC2

Hope AWS team will understand the value of the lost time due to this manual step involved in provisioning certain types of servers for the first time.

Error Msg:
You have requested more instances (1) than your current instance limit of 0 allows for the specified instance type. Please visit http://aws.amazon.com/contact-us/ec2-request to request an adjustment to this limit.

Few other great resources I found that helps to decide which AMI to select for a given instance type:

1. Ubuntu EC2 image locator - http://cloud-images.ubuntu.com/locator/ec2/
2. AWS Linux instance type matrix - http://aws.amazon.com/amazon-linux-ami/instance-type-matrix/

Wednesday, July 02, 2014

google-api python access through refresh token

I couldn't find a single python example on the web that explain how to get an access token to connect to google APIs using a pre-created refresh token.

Note that this is a sample code I wrote so it is far from being production ready. Don't forget to add values to REFRESH_TOKEN, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI and OAUTH_SCOPE variables based on your app settings.

feel free to comment on the code below, Specially on my novice python coding skills.


#!/usr/bin/python

import httplib2
import pprint

from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.client import OAuth2Credentials
from oauth2client import GOOGLE_AUTH_URI
from oauth2client import GOOGLE_REVOKE_URI
from oauth2client import GOOGLE_TOKEN_URI

#Refresh token
REFRESH_TOKEN = ""

# Copy your credentials from the console
CLIENT_ID = ''
CLIENT_SECRET = ''

## Check https://developers.google.com/drive/scopes for all available scopes
OAUTH_SCOPE = ['https://www.googleapis.com/auth/drive','http://localhost:5001/storage/getGDriveAuth']

## Redirect URI for installed apps
REDIRECT_URI = ''


credentials = OAuth2Credentials(None, CLIENT_ID,
                               CLIENT_SECRET, REFRESH_TOKEN, None,
                               GOOGLE_TOKEN_URI, None,
                               revoke_uri=GOOGLE_REVOKE_URI,
                               id_token=None,
                               token_response=None)

# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build('drive', 'v2', http=http)
file = drive_service.files().list().execute()

pprint.pprint(file)
exit();

fixing "npm install jshint" error on #chef #nodejs

Error output:
npm ERR! Error: No compatible version found: date-now@'^0.1.4'
npm ERR! Valid install targets:
npm ERR! ["0.1.0","0.1.1","0.1.3","0.1.2","0.1.4","1.0.0"]


If you get the above error while installing/updating your test servers with #chef, you will need to update the version of npm that is installed on your machine. (ref: https://github.com/npm/npm/issues/5298)

I use the nodejs chef cookbook (http://community.opscode.com/cookbooks/nodejs) to install npm, so updating the npm install version variable to 1.4.19 worked like a charm.

File: /cookbooks/nodejs/attributes/default.rb
Change: default['nodejs']['npm'] = '1.4.19'

While reading through the source I noticed that this cookbook isn't using the install script provided by npmjs site(https://www.npmjs.org/doc/README.html) for installing npm. sounds like an opportunity for any #chef lover to contribute and update the cookbook.