Search in sources :

Example 96 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project nifi by apache.

the class TestCredentialsProviderFactory method testAnonymousCredentials.

@Test
public void testAnonymousCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.USE_ANONYMOUS_CREDENTIALS, "true");
    runner.assertValid();
    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    final AWSCredentials creds = credentialsProvider.getCredentials();
    assertEquals("credentials should be equal", AnonymousAWSCredentials.class, creds.getClass());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 97 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project ORCID-Source by ORCID.

the class S3Utils method createBuckets.

// Create S3 buckets for a given prefix
public static void createBuckets(String bucketPrefix, String accessKey, String secretKey) {
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3 s3 = new AmazonS3Client(credentials);
    String api12JsonPrefix = bucketPrefix + "-api-1-2-json-";
    String api12XMLPrefix = bucketPrefix + "-api-1-2-xml-";
    String api20JsonPrefix = bucketPrefix + "-api-2-0-json-";
    String api20XMLPrefix = bucketPrefix + "-api-2-0-xml-";
    for (int i = 0; i <= 10; i++) {
        char lastCharacter = (i == 10 ? 'x' : Character.forDigit(i, 10));
        if (!s3.doesBucketExist(api12JsonPrefix + lastCharacter)) {
            s3.createBucket((api12JsonPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api12XMLPrefix + lastCharacter)) {
            s3.createBucket((api12XMLPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api20JsonPrefix + lastCharacter)) {
            s3.createBucket((api20JsonPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api20XMLPrefix + lastCharacter)) {
            s3.createBucket((api20XMLPrefix + lastCharacter), Region.EU_Ireland);
        }
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 98 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project jointware by isdream.

the class EC2Main method main.

/**
 * @param args
 */
public static void main(String[] args) {
    AWSCredentials ac = new BasicAWSCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(ac);
    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(Regions.AP_NORTHEAST_1).withCredentials(credentialsProvider).build();
    System.out.println(ec2.getClass().getName());
// for (com.amazonaws.services.ec2.model.Region region : ec2.describeRegions().getRegions()) {
// System.out.println(region.getRegionName());
// }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 99 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project flink by apache.

the class AWSUtilTest method testGetCredentialsProviderNamedProfile.

@Test
public void testGetCredentialsProviderNamedProfile() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "PROFILE");
    testConfig.setProperty(AWSConfigConstants.profileName(AWS_CREDENTIALS_PROVIDER), "foo");
    testConfig.setProperty(AWSConfigConstants.profilePath(AWS_CREDENTIALS_PROVIDER), "src/test/resources/profile");
    AWSCredentialsProvider credentialsProvider = AWSUtil.getCredentialsProvider(testConfig);
    assertTrue(credentialsProvider instanceof ProfileCredentialsProvider);
    AWSCredentials credentials = credentialsProvider.getCredentials();
    assertEquals("22222222222222222222", credentials.getAWSAccessKeyId());
    assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCY2222222222", credentials.getAWSSecretKey());
}
Also used : ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) Properties(java.util.Properties) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 100 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project aws-doc-sdk-examples by awsdocs.

the class DiscoverInstances method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the Namespacename , ServiceName of aws cloud map!\n" + "\n" + "Ex: DiscoverInstances <namespace-name> <service-name> \n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String namespace_name = args[0];
    String service_name = args[1];
    AWSCredentials credentials = null;
    try {
        credentials = new EnvironmentVariableCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot Load Credentials");
    }
    System.out.format("Instances in AWS cloud map %s:\n", namespace_name);
    AWSServiceDiscovery client = AWSServiceDiscoveryClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(System.getenv("AWS_REGION")).build();
    DiscoverInstancesRequest request = new DiscoverInstancesRequest();
    request.setNamespaceName(namespace_name);
    request.setServiceName(service_name);
    DiscoverInstancesResult result = client.discoverInstances(request);
    System.out.println(result.toString());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) DiscoverInstancesResult(com.amazonaws.services.servicediscovery.model.DiscoverInstancesResult) AWSServiceDiscovery(com.amazonaws.services.servicediscovery.AWSServiceDiscovery) AmazonClientException(com.amazonaws.AmazonClientException) DiscoverInstancesRequest(com.amazonaws.services.servicediscovery.model.DiscoverInstancesRequest) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)277 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)181 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)80 Test (org.junit.Test)57 ClientConfiguration (com.amazonaws.ClientConfiguration)53 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)49 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)33 AmazonS3 (com.amazonaws.services.s3.AmazonS3)30 AmazonClientException (com.amazonaws.AmazonClientException)29 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)26 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)15 HashMap (java.util.HashMap)15 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)14 IOException (java.io.IOException)14 AmazonServiceException (com.amazonaws.AmazonServiceException)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)13 Date (java.util.Date)13 SdkClientException (com.amazonaws.SdkClientException)11 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)11 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)11