Example usage for com.amazonaws.auth PropertiesCredentials PropertiesCredentials

List of usage examples for com.amazonaws.auth PropertiesCredentials PropertiesCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth PropertiesCredentials PropertiesCredentials.

Prototype

public PropertiesCredentials(InputStream inputStream) throws IOException 

Source Link

Document

Reads the specified input stream as a stream of Java properties file content and extracts the AWS access key ID and secret access key from the properties.

Usage

From source file:it.polimi.modaclouds.cpimlibrary.taskqueuemng.AmazonTaskQueueFactory.java

License:Apache License

public AmazonTaskQueueFactory(CloudMetadata metadata) {
    AWSCredentials credentials = null;//from  ww  w  .  j a va  2  s  . c  om
    try {
        credentials = new PropertiesCredentials(
                getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.sqs = new AmazonSQSClient(credentials);
    this.info = metadata.getQueueMedatada();
}

From source file:jp.dqneo.amazons3.sample.S3Sample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//from   w  w w.j a  v  a 2 s .c  om
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonS3 s3 = new AmazonS3Client(
            new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties")));

    s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com");

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "2/foo/bar";

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon S3");
    System.out.println("===========================================\n");

    try {

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
         */
        System.out.println("Uploading a new object to S3 from a file\n");
        PutObjectRequest p = new PutObjectRequest(bucketName, key, createSampleFile());
        s3.putObject(p);
        System.out.println("ok\n");

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:jp.dqneo.amazons3.sample.S3TransferProgressSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    credentials = new PropertiesCredentials(
            S3TransferProgressSample.class.getResourceAsStream("AwsCredentials.properties"));

    // TransferManager manages a pool of threads, so we create a
    // single instance and share it throughout our application.
    tx = new TransferManager(credentials);

    bucketName = "s3-transfer-progress-jp.dqneo.amazons3.sample-"
            + credentials.getAWSAccessKeyId().toLowerCase();

    new S3TransferProgressSample();
}

From source file:littleware.apps.fishRunner.FishApp.java

License:LGPL

/**
 * Pulls in configuration from command line or falls back to environment variables
 * of the same name. //from   w  ww .java  2 s  .c  o  m
 * Command line flags: S3_KEY, S3_SECRET, DATABASE_URL, WAR_URI, CONTEXT_ROOT.
 * DATABASE_URL must be of form postgres://user:password@host:port/database -
 * we currently only support postgres database.
 * WAR_URI must be of form s3://... - we currently only support s3: URL's.
 * The app downloads the .war from WAR_URI using AWS credentials S3_KEY and S3_SECRET,
 * launches glassfish on port 8080, establishes a database resource
 * at jndi://jdbc/littleDB connected to DATABASE_URL,
 * and deploys the downloaded WAR to CONTEXT_ROOT if set - 
 * otherwise assumes the .war includes a 
 * glassfish_web.xml that specifies the context root.
 * 
 * @param args command line args
 */
public static void main(String[] args) {
    final Map<String, String> configMap = new HashMap<>();

    configMap.put(Flag.PORT.toString(), "8080");
    for (Flag key : Flag.values()) { // scan environment
        configMap.put(key.toString(), System.getenv(key.toString()));
    }

    { // command line overrides
        String key = null;
        for (String value : args) {
            if (null == key) {
                key = value;
            } else {
                configMap.put(key, value);
                key = null;
            }
        }
    }

    log.log(Level.INFO, "Setting up runtime environment: ");
    for (String key : configMap.keySet()) {
        log.log(Level.INFO, key + "='" + configMap.get(key) + "'");
    }

    try {

        // sanity check
        for (Flag key : EnumSet.of(Flag.CONTEXT_ROOT, Flag.DATABASE_URL, Flag.WAR_URI)) {
            // LOGIN_URI may be null
            if (null == configMap.get(key.toString())) {
                throw new ConfigException(
                        "Parameter must be specified in environment or on command line: " + key);
            }
        }

        final Set<Flag> s3Flags = EnumSet.of(Flag.S3_CREDSFILE, Flag.S3_KEY, Flag.S3_SECRET);
        String s3Key = configMap.get(Flag.S3_KEY.toString());
        String s3Secret = configMap.get(Flag.S3_SECRET.toString());
        String s3CredsFile = configMap.get(Flag.S3_CREDSFILE.toString());

        if ((null == s3Key) || (null == s3Secret)) {
            if (null == s3CredsFile) {
                throw new ConfigException("Must specify (S3_KEY,S3_SECRET) or S3_CREDSFILE");
            }
            final AWSCredentials creds = new PropertiesCredentials(new java.io.File(s3CredsFile));
            s3Key = creds.getAWSAccessKeyId();
            s3Secret = creds.getAWSSecretKey();
        } else if (null != s3CredsFile) {
            throw new ConfigException(
                    "Ambiguous S3 credentials - both (S3_KEY,S3_SECRET) and S3_CREDSFILE defined");
        }

        // finally - launch the app
        final Config config = new Config(configMap.get(Flag.WAR_URI.toString()),
                configMap.get(Flag.CONTEXT_ROOT.toString()), configMap.get(Flag.LOGIN_URI.toString()));

        final int port = Integer.parseInt(configMap.get(Flag.PORT.toString()));
        final Injector ij = Guice.createInjector(new AppModule(config), new FishModule(s3Key, s3Secret,
                new java.net.URI(configMap.get(Flag.DATABASE_URL.toString())), port));

        final FishApp app = ij.getInstance(FishApp.class);
        final GlassFish gf = app.call();

        System.out.print("Enter 'quit' to shutdown server:\n> ");
        System.out.flush();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            final String input = reader.readLine();
            System.out.print("\n> ");
            System.out.flush();
            if (null == input) {
                log.log(Level.INFO, "stdin closed - assuming daemon environment - leaving interactive thread");
                break;
            }
            if (input.equals("quit")) {
                log.log(Level.INFO, "Shutting down ...");
                gf.stop();
                Thread.sleep(5000);
                System.exit(0);
            }
        }
    } catch (Exception ex) {
        log.log(Level.SEVERE, "Failed to launch webapp", ex);
        log.log(Level.INFO, instructions);
        System.exit(1);
    }
}

From source file:llc.rockford.webcast.EC2Handle.java

License:Apache License

private void initializeEC2Handle(String awsCredentialFileLocation) {
    try {/* w w  w. j a  v  a 2  s.  c  o  m*/
        InputStream credentialsAsStream = new FileInputStream(awsCredentialFileLocation);
        AWSCredentials credentials = new PropertiesCredentials(credentialsAsStream);
        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        ec2.setEndpoint(amazonProperties.getEc2_url());
        setEc2Handle(ec2);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(0);
    }
}

From source file:net.henryhu.roxlab2.NotePadProvider.java

License:Apache License

@Override
public boolean onCreate() {
    s3 = new AmazonS3Client(
            new PropertiesCredentials(NotePadProvider.class.getResourceAsStream("AwsCredentials.properties")));

    return true;/*from   w  w w. j a  va  2 s .co  m*/
}

From source file:org.apache.gora.dynamodb.GoraDynamoDBTestDriver.java

License:Apache License

/**
 * Default constructor/*from   w  w  w. jav a2 s  .c o  m*/
 */
public GoraDynamoDBTestDriver() {
    super(DynamoDBStore.class);
    try {
        AWSCredentials credentials;
        File file = new File(awsCredentialsPath + awsCredentialsFile);
        credentials = new PropertiesCredentials(file);
        auth = credentials;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.gora.dynamodb.store.DynamoDBStore.java

License:Apache License

/**
 * Creates the AWSCredentials object based on the properties file.
 * @return AWSCredentials object/*w  w w  .j a v  a 2s .  c  o  m*/
 * @throws FileNotFoundException
 * @throws IllegalArgumentException
 * @throws IOException
 */
private AWSCredentials getCredentials() throws FileNotFoundException, IllegalArgumentException, IOException {

    if (authentication == null) {
        InputStream awsCredInpStr = getClass().getClassLoader().getResourceAsStream(awsCredentialsProperties);
        if (awsCredInpStr == null)
            LOG.info("AWS Credentials File was not found on the classpath!");
        AWSCredentials credentials = new PropertiesCredentials(awsCredInpStr);
        setConf(credentials);
    }
    return (AWSCredentials) authentication;
}

From source file:org.apache.gora.dynamodb.store.DynamoDBUtils.java

License:Apache License

/**
 * Creates the AWSCredentials object based on the properties file.
 *
 * @param clazz//from   w  ww  . ja v  a  2  s.co  m
 * @return
 */
public static PropertiesCredentials getCredentials(Class<?> clazz) {
    PropertiesCredentials awsCredentials = null;
    try {
        InputStream awsCredInpStr = clazz.getClassLoader().getResourceAsStream(AWS_CREDENTIALS_PROPERTIES);
        if (awsCredInpStr == null)
            LOG.error("AWS Credentials File was not found on the classpath!");
        awsCredentials = new PropertiesCredentials(awsCredInpStr);
    } catch (IOException e) {
        LOG.error("Error loading AWS Credentials File from the classpath!", e.getMessage());
        throw new RuntimeException(e);
    }
    return awsCredentials;
}

From source file:org.apache.nifi.processors.aws.AbstractAWSProcessor.java

License:Apache License

protected AWSCredentials getCredentials(final ProcessContext context) {
    final String accessKey = context.getProperty(ACCESS_KEY).evaluateAttributeExpressions().getValue();
    final String secretKey = context.getProperty(SECRET_KEY).evaluateAttributeExpressions().getValue();

    final String credentialsFile = context.getProperty(CREDENTIALS_FILE).getValue();

    if (credentialsFile != null) {
        try {//from  ww w .j  a  v a 2 s.c o m
            return new PropertiesCredentials(new File(credentialsFile));
        } catch (final IOException ioe) {
            throw new ProcessException("Could not read Credentials File", ioe);
        }
    }

    if (accessKey != null && secretKey != null) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }

    return new AnonymousAWSCredentials();

}