Wednesday, June 4, 2014

Access S3 files meta data and other details using Python Boto using Assume Role

Here is the code

import sys
import boto
from boto.sts import STSConnection
from boto.s3.connection import S3Connection
from boto.s3.key import Key


sts_connection = STSConnection()
assumedRoleObject = sts_connection.assume_role(
    role_arn="arn:aws:iam::0000000000:role/xxxx/xxxx-yyyy-zzz",
    role_session_name="AssumeRoleSession1"
)

s3_connection = S3Connection(
    aws_access_key_id=assumedRoleObject.credentials.access_key,
    aws_secret_access_key=assumedRoleObject.credentials.secret_key,
    security_token=assumedRoleObject.credentials.session_token
)


bname="BUCKETNAME"
fname="FILENAME"
bucket = s3_connection.get_bucket(bname)
files=bucket.list(prefix=fname)

for file in files:
        k=bucket.get_key(file)
        print k.get_metadata('key-name')
        print file.name
        print file.size
        print file.last_modified
        print file.get_acl()
        print



1: Lets assume your key name is x-amz-meta-keyname then in the code pass your keyname as "keyname". No need to mention x-amz-meta

Let me know in comments section if his works/doesn't work for you

Wednesday, September 18, 2013

"Unable to execute HTTP request: Connection to https://ec2.amazonaws.com refused" error while executing AWS Java SDK Sample projects

If you are behind proxy then these sample projects will not read proxy from eclipse proxy settings.

to fix this issue you have to add some extra lines of code into your sample projects.


Create a object of ClientConfiguration class and set proxyhost and proxyport properties and then pass this object while creating client (ec2,S3  or sdb etc)

so your init method should look something like this after modification


 private static void init() throws Exception {
    /*
* This credentials provider implementation loads your AWS credentials
* from a properties file at the root of your classpath.
*
*/
   
    ClientConfiguration clientCfg = new ClientConfiguration();
        clientCfg.setProtocol(Protocol.HTTP);

        //setup proxy connection:
        clientCfg.setProxyHost("HTTP_PROXY_IP");
        clientCfg.setProxyPort(8080);
       
        AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();

        ec2 = new AmazonEC2Client(credentialsProvider,clientCfg);
        s3  = new AmazonS3Client(credentialsProvider,clientCfg);
        sdb = new AmazonSimpleDBClient(credentialsProvider,clientCfg);
    }

"Missing requirement: Eclipse Data Tools Platform Amazon SimpleDB UI Plug-in 1.0.0.v201308121803" Error while installing AWS Toolkit for Eclipse

In Eclipse follow below steps to fix this

1: Help -> install new software
2: Type "http://download.eclipse.org/releases/kepler" in the url field
3: Select "Database Development"  and install from the list.
4:  Try to re install  AWS Toolkit, it will work..   :)




Wednesday, March 30, 2011

Get count of messages in a jboss message queue from command prompt

Hi All,

You can also retrieve message count in a particular message queue of jboss, from command prompt, without accessing jmx console.

With command prompt you can automate and send alerts in case message count is above your application threshold

The command to do this is


./twiddle.sh -s localhost:1099 get jboss.messaging.destination:service=Queue,name=ResponseQueue MessageCount


Run this command from jboss bin directory and you can change queue name (in above example it is ResponseQueue) to your application specific queue name

Friday, February 25, 2011

Run Multiple Jboss on Same server

Hi All,

Its very easy to run multiple jboss on same server.

You just need to add one parameter wen you are starting your jboss.

the paramter is

-Djboss.service.binding.set=ports-01

example

./run.sh -c myproj -Djboss.service.binding.set=ports-01 &

to start another jboss on same server use

./run.sh -c myproject -Djboss.service.binding.set=ports-02 &

Just change -Djboss.service.binding.set parameter and you can start many jboss on same server, without any changes in any conf file.

Tuesday, December 14, 2010

Install perl GD module

Hi all,

If you are getting below error while instaling perl GD module module

Could not find gdlib-config in the search path. Please install libgd 2.0.28 or higher


Follow the below steps

1:do yum install gd gd-devel
2: go to cpan
3:then fire install GD

You are all set to go, your GD module should install now

Wednesday, July 7, 2010

How to Log slow queries in postgresql database

Hi All,

Postgresql db can log sql queries that takes more time to execute then specified time limit.


Suppose you want to log sql queries that takes more than 100ms to execute.

Follow the below steps

1: Open postgresql.conf file. You will find this file in data folder of postgres.
2: Modify the below paratmeters

a:logging_collector = on
b:log_min_duration_statement = 100
c:log_duration = on

3: Save and close this file.
4: Restart the DB

Now execute the queries again. P{ostgres will log all the queries in pg_log folder
pg_log folder will be inside your data folder of postgresql.
Name of log file will be in the following format

postgresql-%Y-%m-%d_%H%M%S.log


If you want to change log directory and log file name, just modify these parameters to desired value

#log_directory = 'pg_log' # directory where log files are written,
# can be absolute or relative to PGDATA
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,