import boto.sqs
import boto.sqs.queue
from boto.sqs.message import Message
from boto.sqs.connection import SQSConnection
from boto.exception import SQSError
import sys

import urllib2

def get_key_and_id(url, port):
	resp = urllib2.urlopen(url + ":" + port + "/key", timeout=1)
	return resp.read()

# url=raw_input("Url: ")
url = "http://ec2-52-30-7-5.eu-west-1.compute.amazonaws.com"
# port=raw_input("Port number: ")
port = str(81)


# Get the keys from a specific url and then use them to connect to AWS Service 
list = get_key_and_id(url, port).split(':')

access_key_id = list[0]
secret_access_key = list[1]

# Set up a connection to the AWS service. 
conn = boto.sqs.connect_to_region("eu-west-1", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key)

if len(sys.argv) != 2:
	print "How to use: python <python file name> <new queue name>"
	exit(1)

if conn.lookup(sys.argv[1]) != None:
	print sys.argv[1] + " queue is already existed."
else:
	rs = conn.create_queue(sys.argv[1])
	print "queue " + rs.name + " is now created"
