Java 类com.amazonaws.auth.profile.ProfileCredentialsProvider 实例源码

项目:secondbase    文件:SecretS3IT.java   
@BeforeClass
public static void setupS3() {
    final ProfileCredentialsProvider credentialsProvider
            = new ProfileCredentialsProvider(System.getenv("AWS_PROFILE"));
    s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build();
    bucket = System.getenv("AWS_S3_BUCKET");
    if (! s3Client.doesBucketExist(bucket)) {
        if (System.getenv("AWS_S3_CREATE_BUCKET") == null
                || !Boolean.parseBoolean(System.getenv("AWS_S3_CREATE_BUCKET"))) {
            throw new IllegalStateException("Bucket does not exist and not allowed to create.");
        }
        s3Client.createBucket(bucket);
    }
    S3SecretHandler.setS3CredentialsProvider(credentialsProvider);
    secretHandler = new S3SecretHandler();
}
项目:simple-glacier-client    文件:BaseAmazonGlacierClientAware.java   
protected BaseAmazonGlacierClientAware(String region, String account, String vault) {

    this.region  = region;
    this.account = account;
    this.vault   = vault;

    //@TODO Need to move away from deprecated fashion of acquiring a client
    //@TODO Also, consider supporting other ways of passing credentials (other than relying of local .aws profile)

    // load the credentials from the .aws profile
    this.credentialsProvider = new ProfileCredentialsProvider();

    this.awsClient = new AmazonGlacierClient(this.credentialsProvider);

    // Set Glacier end-point
    this.awsClient.setEndpoint("https://glacier." + this.region + ".amazonaws.com/");
}
项目:filesystem    文件:AbstractS3Action.java   
public AbstractS3Action( FileSystemIO delegate, Map<String, ?> env )
{
    this.delegate = delegate;

    AWSCredentials credentials;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    }
    catch( Exception ex ) {
        throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. "
                                         + "Please make sure that your credentials file is at the correct "
                                         + "location (~/.aws/credentials), and is in valid format.",
                                         ex );
    }

    s3 = new AmazonS3Client( credentials );
    Region region = Region.getRegion( Regions.EU_WEST_1 );
    s3.setRegion( region );

    String n = FileSystemUtils.get( env, BUCKET_READ );
    if( n == null || n.trim().isEmpty() ) {
        n = FileSystemUtils.get( env, BUCKET );
    }
    bucketName = Objects.requireNonNull( n, BUCKET + " or " + BUCKET_READ + " is not defined" );
}
项目:RekognitionS3Batch    文件:Processor.java   
public Processor(ProcessorConfig config) {
    ProfileCredentialsProvider creds = new ProfileCredentialsProvider(config.profile());
    creds.getCredentials(); // credible credential criteria

    if (config.disableCerts())
        System.setProperty("com.amazonaws.sdk.disableCertChecking", "true");

    // Rekognition init
    rek = new AmazonRekognitionClient(creds);
    if (config.endpointOverride())
        rek.setEndpoint(config.endpoint());
    minConfidence = Integer.parseInt(config.confidence());


    // The SQS queue to find jobs on
    sqs = new AmazonSQSClient(creds);
    queueUrl = sqs.createQueue(config.queue()).getQueueUrl();

    // Processors
    if (config.wantCloudSearch())
        processors.add(new CloudSearchIndexer(creds, config.cloudSearch()));
    if (config.wantDynamo())
        processors.add(new DynamoWriter(creds, config.dynamo()));
    if (config.wantTags3())
        processors.add(new S3ObjectTagger(creds, config.tagPrefix()));

    // Executor Service
    int maxWorkers = Integer.parseInt(config.concurrency());
    executor = new ThreadPoolExecutor(
        1, maxWorkers, 30, TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(maxWorkers * 2, false),
        new CallerRunsPolicy() // prevents backing up too many jobs
    );

    maxImagesToProcess = Long.parseLong(config.max());
}
项目:ismartonline    文件:AwsFileManager.java   
@Override
@SuppressWarnings("unused")
public List<AwsFileMiniModel> list(String prefix) {

    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    List<AwsFileMiniModel> files = new ArrayList();

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
    ObjectListing objectListing;

    do {
        objectListing = s3client.listObjects(listObjectsRequest);

        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(" - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")"
                    + " (date = " + objectSummary.getLastModified() + ")");
            files.add(new AwsFileMiniModel(objectSummary.getKey(), objectSummary.getLastModified()));
        }
        listObjectsRequest.setMarker(objectListing.getNextMarker());
    } while (objectListing.isTruncated());

    return files;

}
项目:slim-map-reduce    文件:AWSManager.java   
public AmazonS3 configureS3(){
    /*
     * 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 credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                        "Please make sure that your credentials file is at the correct " +
                        "location (~/.aws/credentials), and is in valid format.",
                        e);
    }
    AmazonS3 s3 = new AmazonS3Client(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    s3.setRegion(usEast1);
    return s3;
}
项目:cerberus-lifecycle-cli    文件:CerberusModule.java   
public static AWSCredentialsProviderChain getAWSCredentialsProviderChain() {
    String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null ?
            System.getenv(CERBERUS_ASSUME_ROLE_ARN) : "";
    String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null ?
            System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) : "";

    STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider =
            new STSAssumeRoleSessionCredentialsProvider
                    .Builder(cerberusRoleToAssume, UUID.randomUUID().toString())
                    .withExternalId(cerberusRoleToAssumeExternalId)
                    .build();

    AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
            new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ProfileCredentialsProvider(),
            sTSAssumeRoleSessionCredentialsProvider,
            new InstanceProfileCredentialsProvider());

    return chain;
}
项目:WeatherPipe    文件:AWSInterfaceTest.java   
@Test
public void testFindOrCreateWeatherPipeJobBucket() {
    String jobID = null; 
    String bucketName = "fdgfhfdx2";
    AWSInterface awsInterface = new AWSInterface(jobID, null);
    jobID = "job1";
    awsInterface = new AWSInterface(jobID, bucketName);
    String output;
    output = awsInterface.FindOrCreateWeatherPipeJobDirectory();
    String answer = "s3n://fdgfhfdx2/";
    assertEquals(answer, output);
    AWSCredentials credentials = new ProfileCredentialsProvider("default").getCredentials();
    // TODO: add better credential searching later

    Region region = Region.getRegion(Regions.US_EAST_1);
    AmazonS3Client s3client = new AmazonS3Client(credentials);
    s3client.setRegion(region);
    s3client.deleteBucket(bucketName);
    System.out.println("FindOrCreateWeatherPipeJobBucket() is ok");
}
项目:dropwizard-sqs-bundle    文件:SqsBundle.java   
AWSCredentials getAwsCredentials() {
    // The ProfileCredentialsProvider will return your [default]
    // credential profile by reading from the credentials file located at
    // (~/.aws/credentials).
    AWSCredentials credentials;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                        "Please make sure that your credentials file is at the correct " +
                        "location (~/.aws/credentials), and is in valid format.",
                e);
    }
    return credentials;
}
项目:fullstop    文件:ExamplePlugin.java   
private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
    final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());

    final AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(
            "arn:aws:iam::ACCOUNT_ID:role/fullstop-role")
                                                             .withDurationSeconds(3600).withRoleSessionName(
                    "fullstop-role");

    final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);

    final BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
            assumeResult.getCredentials()
                        .getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
            assumeResult.getCredentials().getSessionToken());

    final AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
    amazonEC2Client.setRegion(region);

    return amazonEC2Client;
}
项目:bamboo-opsworks    文件:ConfigurationMapCredentialsProvider.java   
@Override
public AWSCredentials getCredentials() {
    // if profile is specified, use that
    final String profile = configuration.get(AWSConstants.PROFILE);
    if(!StringUtils.isNullOrEmpty(profile)) {
        return new ProfileCredentialsProvider(profile).getCredentials();
    }

    // then try access key and secret
    final String accessKeyId = configuration.get(AWSConstants.ACCESS_KEY_ID);
    final String secretAccessKey = configuration.get(AWSConstants.SECRET_ACCESS_KEY);
    if(!StringUtils.isNullOrEmpty(accessKeyId) && !StringUtils.isNullOrEmpty(secretAccessKey)) {
        return new BasicAWSCredentials(accessKeyId, secretAccessKey);
    }

    // fall back to default
    return new DefaultAWSCredentialsProviderChain().getCredentials();
}
项目:oada-ref-impl-java    文件:S3ResourceDAO.java   
/**
 * Upload file to S3.
 *
 * @param local
 *            - local file to upload.
 * @return boolean
 */
boolean uploadS3(File local) {
    boolean retval = false;
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        LOG.debug("Uploading a new object to S3 from local, file name "
                + local.getName());
        s3client.putObject(new PutObjectRequest(bucketName, keyName, local));
        retval = true;
    } catch (AmazonServiceException ase) {
        logAWSServiceException(ase);
    } catch (AmazonClientException ace) {
        logAWSClientException(ace);
    }
    return retval;
}
项目:aws-sdk-java-archetype    文件:AwsSdkSample.java   
/**
 * The only information needed to create a client are security credentials -
 * your AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints have defaults provided.
 *
 * Additional client parameters, such as proxy configuration, can be specified
 * in an optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private static void init() throws Exception {
    /*
     * ProfileCredentialsProvider loads AWS security credentials from a
     * .aws/config file in your home directory.
     *
     * These same credentials are used when working with other AWS SDKs and the AWS CLI.
     *
     * You can find more information on the AWS profiles config file here:
     * http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
     */
    File configFile = new File(System.getProperty("user.home"), ".aws/credentials");
    AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider(
        new ProfilesConfigFile(configFile), "default");

    if (credentialsProvider.getCredentials() == null) {
        throw new RuntimeException("No AWS security credentials found:\n"
                + "Make sure you've configured your credentials in: " + configFile.getAbsolutePath() + "\n"
                + "For more information on configuring your credentials, see "
                + "http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html");
    }

    ec2 = new AmazonEC2Client(credentialsProvider);
    s3  = new AmazonS3Client(credentialsProvider);
}
项目:debs14-grand-challenge    文件:S3Spout.java   
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
    super.open(map, topologyContext, spoutOutputCollector);
    try {
        if (map.containsKey(Constants.S3_BUCKET_NAME)) {
            bucketName = (String) map.get(Constants.S3_BUCKET_NAME);
        }
        if (map.containsKey(Constants.S3_KEY)) {
            key = (String) map.get(Constants.S3_KEY);
        }
        credentials = new ProfileCredentialsProvider().getCredentials();
        s3Client = new AmazonS3Client(credentials);
        object = s3Client.getObject(
                new GetObjectRequest(bucketName, key));
        objectData = object.getObjectContent();
        reader = new BufferedReader(new InputStreamReader(objectData));
    } catch (Exception e) {
        System.err.println("Error connecting to bucket." + e.getMessage());
    }
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_noExplicitCredentialsProviderConfigured_configuresDefaultAwsCredentialsProviderChainWithInstanceProfile() throws Exception {
    // Arrange
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);

    // Act
    this.context.refresh();

    // Assert
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_accessKeyAndSecretKeyConfigured_configuresStaticCredentialsProviderWithAccessAndSecretKey() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.accessKey:foo",
            "cloud.aws.credentials.secretKey:bar").applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProviderChain.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(AWSStaticCredentialsProvider.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));

    assertEquals("foo", awsCredentialsProvider.getCredentials().getAWSAccessKeyId());
    assertEquals("bar", awsCredentialsProvider.getCredentials().getAWSSecretKey());

}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_instanceProfileConfigured_configuresInstanceProfileCredentialsProvider() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.instanceProfile").applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_profileNameConfigured_configuresProfileCredentialsProvider() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.profileName:test").applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));

    assertEquals("test", ReflectionTestUtils.getField(credentialsProviders.get(1), "profileName"));
}
项目:spring-cloud-aws    文件:ContextCredentialsAutoConfigurationTest.java   
@Test
public void credentialsProvider_profileNameAndPathConfigured_configuresProfileCredentialsProvider() throws IOException {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ContextCredentialsAutoConfiguration.class);
    TestPropertyValues.of(
            "cloud.aws.credentials.profileName:customProfile",
            "cloud.aws.credentials.profilePath:" + new ClassPathResource(getClass().getSimpleName() + "-profile", getClass()).getFile().getAbsolutePath()).applyTo(this.context);
    this.context.refresh();
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class);
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(2, credentialsProviders.size());
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(0)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(1)));

    ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders.get(1);
    assertEquals("testAccessKey", provider.getCredentials().getAWSAccessKeyId());
    assertEquals("testSecretKey", provider.getCredentials().getAWSSecretKey());
}
项目:spring-cloud-aws    文件:ContextCredentialsConfigurationRegistrarTest.java   
@Test
public void credentialsProvider_configWithProfileNameAndNoProfilePath_profileCredentialsProviderConfigured() throws Exception {
    //Arrange
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithProfileAndDefaultProfilePath.class);

    //Act
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AWSCredentialsProvider.class);

    //Assert
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(1, credentialsProviders.size());
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(0)));

    ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders.get(0);
    assertEquals("test", ReflectionTestUtils.getField(provider, "profileName"));
}
项目:spring-cloud-aws    文件:ContextCredentialsConfigurationRegistrarTest.java   
@Test
public void credentialsProvider_configWithAllProviders_allCredentialsProvidersConfigured() throws Exception {
    //Arrange
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithAllProviders.class);

    //Act
    AWSCredentialsProvider awsCredentialsProvider = this.context.getBean(AWSCredentialsProvider.class);

    //Assert
    assertNotNull(awsCredentialsProvider);

    @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders =
            (List<CredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProvider, "credentialsProviders");
    assertEquals(3, credentialsProviders.size());
    assertTrue(AWSStaticCredentialsProvider.class.isInstance(credentialsProviders.get(0)));
    assertTrue(EC2ContainerCredentialsProviderWrapper.class.isInstance(credentialsProviders.get(1)));
    assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(2)));
}
项目:tcc-oada    文件:S3ResourceDAO.java   
/**
 * Upload file to S3.
 *
 * @param local
 *            - local file to upload.
 * @return boolean
 */
boolean uploadS3(File local) {
    boolean retval = false;
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        LOG.debug("Uploading a new object to S3 from local, file name "
                + local.getName());
        s3client.putObject(new PutObjectRequest(bucketName, keyName, local));
        retval = true;
    } catch (AmazonServiceException ase) {
        logAWSServiceException(ase);
    } catch (AmazonClientException ace) {
        logAWSClientException(ace);
    }
    return retval;
}
项目:dataset-lib    文件:S3Provider.java   
public void remove(Object[] params) {
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        s3client.deleteObject(new DeleteObjectRequest(bucketName, params[0].toString()));
    } 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 " +
            "an internal error while trying to " +
            "communicate with S3, " +
            "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}
项目:dataset-lib    文件:S3Provider.java   
public Object get(Object[] params) {
    AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, params[0].toString()));
        InputStream objectData = object.getObjectContent();
        byte[] bytes = IOUtils.toByteArray(is);
        ByteBuffer b = ByteBuffer.wrap(bytes);
        return b;
    } 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 " +
            "an internal error while trying to " +
            "communicate with S3, " +
            "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}
项目:dataset-lib    文件:S3Provider.java   
public void put(Object[] params) {
    String key = params[0].toString();
    File file = new File(params[0].toString());
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        s3client.putObject(new PutObjectRequest(bucketName, key, file));
    } 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 " +
            "an internal error while trying to " +
            "communicate with S3, " +
            "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}
项目:webcrawler    文件:AppConfig.java   
@Bean
public AmazonDynamoDBAsync getDynamoDBClient() {

    return AmazonDynamoDBAsyncClientBuilder.standard()
            .withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER))
            .withRegion(Regions.AP_SOUTHEAST_2)
            .build();

}
项目:webcrawler    文件:AppConfig.java   
@Bean
public AmazonSQSAsync getSQSClient() {

    return AmazonSQSAsyncClientBuilder.standard()
            .withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER))
            .withRegion(Regions.AP_SOUTHEAST_2)
            .build();

}
项目:webcrawler    文件:AppConfig.java   
@Bean
public SQSConnectionFactory sqsConnectionFactory() throws JMSException {

    return new SQSConnectionFactory(
            new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard()
                    .withRegion(Regions.AP_SOUTHEAST_2)
                    .withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER))
    );
}
项目:opentest    文件:PutS3Object.java   
@Override
public void run() {
    super.run();

    String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
    String bucket = this.readStringArgument("bucket");
    String objectKey = this.readStringArgument("objectKey");
    String sourceFilePath = this.readStringArgument("sourceFile");

    File sourceFile = new File(sourceFilePath);
    if (sourceFile.exists()) {
        try {
            AmazonS3 s3Client = new AmazonS3Client(
                    new ProfileCredentialsProvider(awsCredentialsProfile));
            s3Client.putObject(new PutObjectRequest(bucket, objectKey, sourceFile));
         } catch (Exception ex) {
           throw new RuntimeException(String.format(
                    "Failed to upload file \"%s\" to S3 bucket \"%s\"",
                    sourceFilePath,
                    bucket), ex);
        } 
    } else {
        throw new RuntimeException(String.format(
                "Source file \"%s\" doesn't exist",
                sourceFilePath));
    }    
}
项目:opentest    文件:GetS3Metadata.java   
@Override
public void run() {
    super.run();

    String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
    String bucket = this.readStringArgument("bucket");
    String objectKey = this.readStringArgument("objectKey");

    AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
    ObjectMetadata metadata = s3Client.getObjectMetadata(
            new GetObjectMetadataRequest(bucket, objectKey));

    try {
        Date expirationTime = metadata.getExpirationTime();
        if (expirationTime != null) {
            this.writeOutput("expirationTime", metadata.getExpirationTime().getTime());
        } else {
            this.writeOutput("expirationTime", null);
        }
        this.writeOutput("lastModified", metadata.getLastModified().getTime());
        this.writeOutput("userMetadata", metadata.getUserMetadata());
        this.writeOutput("size", metadata.getContentLength());
        this.writeOutput("storageClass", metadata.getStorageClass());
        this.writeOutput("versionId", metadata.getVersionId());
    } catch (Exception ex) {
        throw new RuntimeException(String.format(
                "Failed to get object metadata for object key %s in bucket %s",
                objectKey,
                bucket), ex);
    }
}
项目:opentest    文件:GetS3Object.java   
@Override
public void run() {
    super.run();

    String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
    String bucket = this.readStringArgument("bucket");
    String objectKey = this.readStringArgument("objectKey");
    String targetFilePath = this.readStringArgument("targetFile");
    Boolean overwrite = this.readBooleanArgument("overwrite", false);

    AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
    S3Object object = s3Client.getObject(
            new GetObjectRequest(bucket, objectKey));
    InputStream objectDataStream = object.getObjectContent();

    if (targetFilePath != null) {
        File targetFile = new File(targetFilePath);
        if (!targetFile.isAbsolute()) {
            targetFile = Paths.get(this.getActor().getTempDir().getAbsolutePath(), targetFilePath).toFile();
        }
        targetFile.getParentFile().mkdirs();

        try {
            if (overwrite) {
                Files.copy(objectDataStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            } else {
                Files.copy(objectDataStream, targetFile.toPath());
            }
        } catch (Exception ex) {
            throw new RuntimeException(String.format(
                    "Failed to transfer data from the input stream into file %s",
                    targetFilePath), ex);
        }

        this.writeArgument("targetFile", targetFile.getAbsolutePath());
    } else {
        // TODO: Make targetFile arg optional so this branch can execute.
        // Read data in memory and write it to an output value
    }
}
项目:CloudPrime    文件:Connection.java   
public static String getOwnIP()
{
    AWSCredentials credentials = null;
    try
    {
        credentials = new ProfileCredentialsProvider().getCredentials();
    }
    catch(Exception e){}

    AmazonEC2 ec2 = new AmazonEC2Client(credentials);       

    ec2.setEndpoint("ec2.eu-west-1.amazonaws.com");
    DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
    List<Reservation> reservations = describeInstancesResult.getReservations();
    ArrayList<Instance> listOfInstances = new ArrayList<Instance>();
    for(Reservation reservation : reservations)
        listOfInstances.addAll(reservation.getInstances());

    String ownIP = null;
    String ownInstanceID = checkInstanceId();
    for(Instance instance: listOfInstances)
    {
        if(instance.getInstanceId().equals(ownInstanceID))
            ownIP = instance.getPublicIpAddress();
    }

    return ownIP;
}
项目:CloudPrime    文件:DynamoEntry.java   
public static DynamoEntry getFromMSS(String parameter)
{
    dynamoDB = new AmazonDynamoDBClient(new ProfileCredentialsProvider().getCredentials());
    dynamoDB.setRegion(Region.getRegion(Regions.EU_WEST_1));

    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("Parameter", new Condition().withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue(parameter)));

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.setKeyConditions(keyConditions);
    queryRequest.withTableName("MSS");

    QueryResult result = dynamoDB.query(queryRequest);
    //se houver um pedido ja tratado no MSS getCount > 0, caso contrario nao existe
    if(result.getCount() == 0)
        return null;
    else
    {
        //vamos buscar o rank
        Map<String, AttributeValue> queryResult = result.getItems().get(0);
        String rank = "";
        boolean runningState = false;

        for (Map.Entry<String, AttributeValue> entry  : queryResult.entrySet()) 
        {
            if(entry.getKey().equals("Rank"))
                rank = entry.getValue().getN();
            else if(entry.getKey().equals("Running"))
                runningState = entry.getValue().getBOOL();
        }
        DynamoEntry rankResult = new DynamoEntry(new BigInteger(rank), runningState);           
        return rankResult;
    }
}
项目:CloudPrime    文件:InstTool.java   
@Override
public void run() {
    try {
        FileInputStream logFile = new FileInputStream("logIntermedio.txt");
        BufferedReader bufReader = new BufferedReader(new InputStreamReader(logFile));

        String line;

        while ((line = bufReader.readLine()) != null) {
            String[] parts = line.split(":");

            if (parts[0].equals(threadID)) {
                AmazonDynamoDBClient dynamoDB = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
                dynamoDB.setRegion(Region.getRegion(Regions.EU_WEST_1));

                String[] parameterParts = parts[1].split("=");
                String parameter = parameterParts[1];

                QueryResult result = getEntryDynamo(parameter, dynamoDB);

                if (result.getCount() == 0) // se a query nao retornar nada significa que nao temos nada no dynamo sobre este parametro
                {
                    putDynamo(parameter, metricas.i_count, metricas.b_count, metricas.fieldLoadCount,
                            metricas.loadCount, dynamoDB, true, threadID, null);
                } else { //caso contrario vamos buscar as metricas que temos para atualiza las
                    Map<String, AttributeValue> queryResult = result.getItems().get(0);
                    // runningValue fica a true se Running estiver a true, se ja estiver a false entao ja temos as metricas finais para este parametro portanto nao atualizamos o dynamo
                    boolean runningValue = queryResult.values().contains(new AttributeValue().withBOOL(true));
                    if (runningValue) {
                        putDynamo(parameter, metricas.i_count, metricas.b_count, metricas.fieldLoadCount,
                                metricas.loadCount, dynamoDB, true, threadID, result);
                    }
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:amazon-kinesis-video-streams-parser-library    文件:KinesisVideoExampleTest.java   
@Ignore
@Test
public void testExample() throws InterruptedException, IOException {
    KinesisVideoExample example = KinesisVideoExample.builder().region(Regions.US_WEST_2)
            .streamName("myTestStream")
            .credentialsProvider(new ProfileCredentialsProvider())
            .inputVideoStream(TestResourceUtil.getTestInputStream("clusters.mkv"))
            .build();

    example.execute();
    Assert.assertEquals(5, example.getFragmentsPersisted());
    Assert.assertEquals(5, example.getFragmentsRead());
}
项目:intellij-idea-plugin-connector-for-aws-lambda    文件:ConnectorModel.java   
public ConnectorModel(Regions region, String profileName) {

        ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider(profileName);

        awsLambdaClient = AWSLambdaClientBuilder.standard()
                .withRegion(region)
                .withCredentials(profileCredentialsProvider)
                .build();
    }
项目:RekognitionS3Batch    文件:Scanner.java   
public Scanner(ScanConfig config) {
    opt = config;
    ProfileCredentialsProvider creds = new ProfileCredentialsProvider(opt.profile());
    creds.getCredentials(); // credible credential criteria
    s3 = new AmazonS3Client(creds);
    sqs = new AmazonSQSClient(creds);

    CreateQueueResult queueResult = sqs.createQueue(opt.queue());
    queueUrl = queueResult.getQueueUrl();

    filter = Pattern.compile(opt.filter(), Pattern.CASE_INSENSITIVE);
    max = Long.parseLong(opt.max());
}
项目:aml    文件:ApiImporter.java   
@SuppressWarnings("deprecation")
public ApiImporter(String profile, String accessKey, String secret) {
    if (accessKey != null && secret != null) {
        credentialsProvider=new AWSCredentialsProvider() {

            @Override
            public void refresh() {
            }

            @Override
            public AWSCredentials getCredentials() {
                return new AWSCredentials() {

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

                    @Override
                    public String getAWSAccessKeyId() {
                        return accessKey;
                    }
                };
            }
        };
    } else {
        credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
                new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(profile),
                new InstanceProfileCredentialsProvider());
    }
    amazonApiGatewayClient = new AmazonApiGatewayClient(credentialsProvider);
}
项目:lambadaframework    文件:AuthenticationInfoAWSCredentialsProviderChain.java   
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(
            new InstanceProfileCredentialsProvider(),
            new ProfileCredentialsProvider(),
            new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}
项目:gradle-beanstalk-plugin    文件:DeployTask.java   
@TaskAction
protected void deploy() {
    String versionLabel = getVersionLabel();

    AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(beanstalk.getProfile()));

    BeanstalkDeployer deployer = new BeanstalkDeployer(beanstalk.getS3Endpoint(), beanstalk.getBeanstalkEndpoint(), credentialsProvider);

    File warFile = getProject().files(war).getSingleFile();
    deployer.deploy(warFile, deployment.getApplication(), deployment.getEnvironment(), deployment.getTemplate(), versionLabel);
}