Example usage for com.amazonaws.auth AWSCredentials AWSCredentials

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

Introduction

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

Prototype

AWSCredentials

Source Link

Usage

From source file:ch.admin.isb.hermes5.tools.deploysupport.DeploySupport.java

License:Apache License

private AWSCredentials credentials() {
    return new AWSCredentials() {

        @Override/*from w  w  w . jav  a2 s  .  co  m*/
        public String getAWSSecretKey() {
            return secretKey;
        }

        @Override
        public String getAWSAccessKeyId() {
            return accessKeyId;
        }
    };
}

From source file:com.aipo.aws.AWSContext.java

License:Open Source License

private void setUp(String resourcePath, ServletContext context) {
    Properties properties = new Properties();
    try {//from w w  w.j  ava 2 s . c o  m
        InputStream resourceAsStream = new FileInputStream(resourcePath);

        final String key = AEBEnvironmentProperties.AWS_ACCESS_KEY_ID;
        final String secret = AEBEnvironmentProperties.AWS_SECRET_KEY;
        if (key != null && key.length() > 0 && secret != null && secret.length() > 0) {
            awsCredentials = new AWSCredentials() {

                @Override
                public String getAWSAccessKeyId() {
                    return key;
                }

                @Override
                public String getAWSSecretKey() {
                    return secret;
                }
            };
        } else {
            awsCredentials = new PropertiesCredentials(resourceAsStream);
        }

        resourceAsStream = new FileInputStream(resourcePath);
        try {
            properties.load(resourceAsStream);
        } finally {
            try {
                resourceAsStream.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        System.out.println("'" + resourcePath + "' doesn't load.");
    }

    sdbEndpoint = properties.getProperty("sdbEndpoint");
    s3Endpoint = properties.getProperty("s3Endpoint");
    rdsEndpoint = properties.getProperty("rdsEndpoint");
    sqsEndpoint = properties.getProperty("sqsEndpoint");
    snsEndpoint = properties.getProperty("snsEndpoint");
    sesEndpoint = properties.getProperty("sesEndpoint");
    cloudWatchEndpoint = properties.getProperty("cloudWatchEndpoint");
    prefix = properties.getProperty("prefix");
}

From source file:com.altoukhov.svsync.fileviews.S3FileSpace.java

License:Apache License

private AWSCredentials wrapCredentials(final String id, final String secret) {
    return new AWSCredentials() {

        @Override//from   www  .j a v a  2  s.  c  om
        public String getAWSAccessKeyId() {
            return id;
        }

        @Override
        public String getAWSSecretKey() {
            return secret;
        }
    };
}

From source file:com.aws.sampleImage.url.LambdaFunctionImageURLCrawlerHandler.java

private static void init() {
    AWSCredentials awsCredentials = new AWSCredentials() {

        @Override/*from ww w .  j a  v  a2  s  .c o m*/
        public String getAWSSecretKey() {
            return "M2HnD68DXBmeNYcuxO0PDVuRPjJONDLiRXTFwygN";//M2HnD68DXBmeNYcuxO0PDVuRPjJONDLiRXTFwygN
        }

        @Override
        public String getAWSAccessKeyId() {
            return "AKIAJ5LSYQCPXHSNYVYQ";//AKIAJ5LSYQCPXHSNYVYQ
        }
    };

    //dynamoDB = new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider());
    dynamoDB = new AmazonDynamoDBClient(awsCredentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
    System.out.println("^^^^^  DynamoDB created successfully --> " + dynamoDB);
}

From source file:com.epam.dlab.auth.modules.AwsSecurityServiceModule.java

License:Apache License

private AWSCredentials devAwsCredentials() {
    return new AWSCredentials() {
        @Override//  w  w  w  .  j a  va  2s  . co m
        public String getAWSAccessKeyId() {
            return "access_key";
        }

        @Override
        public String getAWSSecretKey() {
            return "secret_key";
        }
    };
}

From source file:com.example.base.KinesisConnectorExecutor.java

License:Open Source License

public KinesisConnectorExecutor(String configFile, String content) {
    this.content = content;
    InputStream configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile);

    if (configStream == null) {
        String msg = "Could not find resource " + configFile + " in the classpath";
        throw new IllegalStateException(msg);
    }//from   ww w .j  a v a  2 s  . c  om
    properties = new Properties();
    try {
        properties.load(configStream);
        configStream.close();
    } catch (IOException e) {
        String msg = "Could not load properties file " + configFile + " from classpath";
        throw new IllegalStateException(msg, e);
    }
    AWSCredentialsProvider prov = new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return "AKIAJMOK3KHKIRPDXQBA";
                }

                @Override
                public String getAWSSecretKey() {
                    return "s2MEQ6k4acTakezkqFdoYWw909DqLwIro8ZeR9Iy";
                }
            };
        }

        @Override
        public void refresh() {

        }
    };
    this.config = new KinesisConnectorConfiguration(properties, prov);
    setupAWSResources();
    setupInputStream();

    // Initialize executor with configurations
    super.initialize(config, content);
}

From source file:com.example.base.StreamSource.java

License:Open Source License

/**
 * Creates a new StreamSource./*  w ww .j a  v a 2s . c o m*/
 * 
 * @param config
 *        Configuration to determine which stream to put records to and get {@link AWSCredentialsProvider}
 * @param inputFile
 *        File containing record data to emit on each line
 * @param loopOverStreamSource
 *        Loop over the stream source to continually put records
 */
public StreamSource(String content, KinesisConnectorConfiguration config, String inputFile,
        boolean loopOverStreamSource) {
    this.config = config;
    this.content = content;
    this.inputFile = inputFile;
    this.loopOverInputFile = loopOverStreamSource;
    this.objectMapper = new ObjectMapper();
    kinesisClient = new AmazonKinesisClient(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return "AKIAJMOK3KHKIRPDXQBA";
                }

                @Override
                public String getAWSSecretKey() {
                    return "s2MEQ6k4acTakezkqFdoYWw909DqLwIro8ZeR9Iy";
                }
            };
        }

        @Override
        public void refresh() {

        }
    });
    kinesisClient.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    if (config.KINESIS_ENDPOINT != null) {
        kinesisClient.setEndpoint(config.KINESIS_ENDPOINT);
    }
    KinesisUtils.createInputStream(config);
}

From source file:com.numenta.taurus.service.TaurusClient.java

License:Open Source License

/**
 * Construct Taurus API client.//from   w ww .  j  a  va  2s .  com
 *
 * @param provider  The AWS credential provider to use.
 *                  Usually {@link TaurusApplication#getAWSCredentialProvider()}
 * @param serverUrl DynamoDB Server. Use "http://10.0.2.2:8300" for local server or
 *                  null for AWS
 */
public TaurusClient(AWSCredentialsProvider provider, String serverUrl) {
    _server = serverUrl;
    AWSCredentialsProvider credentialsProvider = provider;
    if (credentialsProvider == null) {
        // Use Dummy credentials for local server
        credentialsProvider = new StaticCredentialsProvider(new AWSCredentials() {
            public String getAWSAccessKeyId() {
                // Returns dummy value
                return "taurus";
            }

            @Override
            public String getAWSSecretKey() {
                // Returns dummy value
                return "taurus";
            }
        });
    }
    _awsClient = new AmazonDynamoDBClient(credentialsProvider);
    if (BuildConfig.REGION != null) {
        // Override default region
        _awsClient.setRegion(Region.getRegion(Regions.fromName(BuildConfig.REGION)));
    }
    if (_server != null) {
        // Override server endpoint, Usually the local DynamoDB server
        _awsClient.setEndpoint(_server);
    }
}

From source file:com.topera.epoch.service.S3Util.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//w  ww  .  j  av  a 2  s . c o  m
     * Create your credentials file at ~/.aws/credentials (C:\Users\USER_NAME\.aws\credentials for Windows users) 
     * and save the following lines after replacing the underlined values with your own.
     *
     * [default]
     * aws_access_key_id = YOUR_ACCESS_KEY_ID
     * aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
     */
    AWSCredentials creds = new AWSCredentials() {

        public String getAWSSecretKey() {
            // TODO Auto-generated method stub
            return "5VVtmI7vcecuVbw8JsG4uo2O1/9RwwLHrTT01Itz";
        }

        public String getAWSAccessKeyId() {
            // TODO Auto-generated method stub
            return "AKIAJCMYALI46A2DIPRQ";
        }
    };

    AmazonS3 s3 = new AmazonS3Client(creds);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "MyObjectKey";

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

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
         */
        System.out.println("Creating bucket " + bucketName + "\n");
        s3.createBucket(bucketName);

        /*
         * List the buckets in your account
         */
        System.out.println("Listing buckets");
        for (Bucket bucket : s3.listBuckets()) {
            System.out.println(" - " + bucket.getName());
        }
        System.out.println();

        /*
         * 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");
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
         */
        System.out.println("Downloading an object");
        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());

        /*
         * List objects in your bucket by prefix - There are many options for
         * listing the objects in your bucket.  Keep in mind that buckets with
         * many objects might truncate their results when listing their objects,
         * so be sure to check if the returned object listing is truncated, and
         * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
         * additional results.
         */
        System.out.println("Listing objects");
        ObjectListing objectListing = s3
                .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My"));
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(
                    " - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
        }
        System.out.println();

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
         */
        System.out.println("Deleting an object\n");
        s3.deleteObject(bucketName, key);

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
         */
        System.out.println("Deleting bucket " + bucketName + "\n");
        s3.deleteBucket(bucketName);
    } 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:com.universal.storage.UniversalProfileCredentialsProvider.java

License:Open Source License

/**
 * Returns AWSCredentials which the caller can use to authorize an AWS request. Each implementation of
 * AWSCredentialsProvider can chose its own strategy for loading credentials. For example, an implementation 
 * might load credentials from an existing key management system, or load new credentials when credentials are 
 * rotated./*from w w w  .  j  av a 2s .c om*/
 * 
 * This method is overridden to get the access key from the settings in context.
 * 
 * Returns a singleton instance.
 */
public AWSCredentials getCredentials() {
    if (credentials == null) {
        credentials = new AWSCredentials() {
            public String getAWSAccessKeyId() {
                return UniversalProfileCredentialsProvider.this.settings.getAWSAccessKeyId();
            }

            public String getAWSSecretKey() {
                return UniversalProfileCredentialsProvider.this.settings.getAWSSecretKey();
            }
        };
    }

    return credentials;
}