Search in sources :

Example 26 with AWSStaticCredentialsProvider

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

the class Main method main.

public static void main(String[] args) {
    AWSCredentials credentials_profile = null;
    try {
        credentials_profile = new ProfileCredentialsProvider("default").getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load credentials from .aws/credentials file. " + "Make sure that the credentials file exists and the profile name is specified within it.", e);
    }
    AmazonElasticMapReduce emr = AmazonElasticMapReduceClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials_profile)).withRegion(Regions.US_WEST_1).build();
    // Run a bash script using a predefined step in the StepFactory helper class
    StepFactory stepFactory = new StepFactory();
    StepConfig runBashScript = new StepConfig().withName("Run a bash script").withHadoopJarStep(stepFactory.newScriptRunnerStep("s3://jeffgoll/emr-scripts/create_users.sh")).withActionOnFailure("CONTINUE");
    // Run a custom jar file as a step
    HadoopJarStepConfig hadoopConfig1 = new HadoopJarStepConfig().withJar(// replace with the location of the jar to run as a step
    "s3://path/to/my/jarfolder").withMainClass(// optional main class, this can be omitted if jar above has a manifest
    "com.my.Main1").withArgs(// optional list of arguments to pass to the jar
    "--verbose");
    StepConfig myCustomJarStep = new StepConfig("RunHadoopJar", hadoopConfig1);
    AddJobFlowStepsResult result = emr.addJobFlowSteps(new AddJobFlowStepsRequest().withJobFlowId(// replace with cluster id to run the steps
    "j-xxxxxxxxxxxx").withSteps(runBashScript, myCustomJarStep));
    System.out.println(result.getStepIds());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonClientException(com.amazonaws.AmazonClientException) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) StepFactory(com.amazonaws.services.elasticmapreduce.util.StepFactory) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException) AmazonElasticMapReduce(com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce)

Example 27 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider 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)

Example 28 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project YCSB by brianfrankcooper.

the class DynamoDBClient method init.

@Override
public void init() throws DBException {
    String debug = getProperties().getProperty("dynamodb.debug", null);
    if (null != debug && "true".equalsIgnoreCase(debug)) {
        LOGGER.setLevel(Level.DEBUG);
    }
    String configuredEndpoint = getProperties().getProperty("dynamodb.endpoint", null);
    String credentialsFile = getProperties().getProperty("dynamodb.awsCredentialsFile", null);
    String primaryKey = getProperties().getProperty("dynamodb.primaryKey", null);
    String primaryKeyTypeString = getProperties().getProperty("dynamodb.primaryKeyType", null);
    String consistentReads = getProperties().getProperty("dynamodb.consistentReads", null);
    String connectMax = getProperties().getProperty("dynamodb.connectMax", null);
    String configuredRegion = getProperties().getProperty("dynamodb.region", null);
    if (null != connectMax) {
        this.maxConnects = Integer.parseInt(connectMax);
    }
    if (null != consistentReads && "true".equalsIgnoreCase(consistentReads)) {
        this.consistentRead = true;
    }
    if (null != configuredEndpoint) {
        this.endpoint = configuredEndpoint;
    }
    if (null == primaryKey || primaryKey.length() < 1) {
        throw new DBException("Missing primary key attribute name, cannot continue");
    }
    if (null != primaryKeyTypeString) {
        try {
            this.primaryKeyType = PrimaryKeyType.valueOf(primaryKeyTypeString.trim().toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new DBException("Invalid primary key mode specified: " + primaryKeyTypeString + ". Expecting HASH or HASH_AND_RANGE.");
        }
    }
    if (this.primaryKeyType == PrimaryKeyType.HASH_AND_RANGE) {
        // When the primary key type is HASH_AND_RANGE, keys used by YCSB
        // are range keys so we can benchmark performance of individual hash
        // partitions. In this case, the user must specify the hash key's name
        // and optionally can designate a value for the hash key.
        String configuredHashKeyName = getProperties().getProperty("dynamodb.hashKeyName", null);
        if (null == configuredHashKeyName || configuredHashKeyName.isEmpty()) {
            throw new DBException("Must specify a non-empty hash key name when the primary key type is HASH_AND_RANGE.");
        }
        this.hashKeyName = configuredHashKeyName;
        this.hashKeyValue = getProperties().getProperty("dynamodb.hashKeyValue", DEFAULT_HASH_KEY_VALUE);
    }
    if (null != configuredRegion && configuredRegion.length() > 0) {
        region = configuredRegion;
    }
    try {
        AmazonDynamoDBClientBuilder dynamoDBBuilder = AmazonDynamoDBClientBuilder.standard();
        dynamoDBBuilder = null == endpoint ? dynamoDBBuilder.withRegion(this.region) : dynamoDBBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(this.endpoint, this.region));
        dynamoDB = dynamoDBBuilder.withClientConfiguration(new ClientConfiguration().withTcpKeepAlive(true).withMaxConnections(this.maxConnects)).withCredentials(new AWSStaticCredentialsProvider(new PropertiesCredentials(new File(credentialsFile)))).build();
        primaryKeyName = primaryKey;
        LOGGER.info("dynamodb connection created with " + this.endpoint);
    } catch (Exception e1) {
        LOGGER.error("DynamoDBClient.init(): Could not initialize DynamoDB client.", e1);
    }
}
Also used : AmazonDynamoDBClientBuilder(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) File(java.io.File) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 29 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project zeppelin by apache.

the class S3NotebookRepoTest method setUp.

@Before
public void setUp() throws IOException {
    String bucket = "test-bucket";
    notebookRepo = new S3NotebookRepo();
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_S3_ENDPOINT.getVarName(), s3Proxy.getUri().toString());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_S3_BUCKET.getVarName(), bucket);
    System.setProperty("aws.accessKeyId", s3Proxy.getAccessKey());
    System.setProperty("aws.secretKey", s3Proxy.getSecretKey());
    notebookRepo.init(conf);
    // create bucket for notebook
    AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(s3Proxy.getAccessKey(), s3Proxy.getSecretKey()))).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Proxy.getUri().toString(), Regions.US_EAST_1.getName())).build();
    s3Client.createBucket(bucket);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Before(org.junit.Before)

Example 30 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project ignite by apache.

the class DiscoveryInTheCloud method awsElbExample.

public static void awsElbExample() {
    // tag::awsElb[]
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    BasicAWSCredentials creds = new BasicAWSCredentials("yourAccessKey", "yourSecreteKey");
    TcpDiscoveryElbIpFinder ipFinder = new TcpDiscoveryElbIpFinder();
    ipFinder.setRegion("yourElbRegion");
    ipFinder.setLoadBalancerName("yourLoadBalancerName");
    ipFinder.setCredentialsProvider(new AWSStaticCredentialsProvider(creds));
    spi.setIpFinder(ipFinder);
    IgniteConfiguration cfg = new IgniteConfiguration();
    // Override default discovery SPI.
    cfg.setDiscoverySpi(spi);
    // Start the node.
    Ignition.start(cfg);
// end::awsElb[]
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryElbIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.elb.TcpDiscoveryElbIpFinder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)63 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)44 AWSCredentials (com.amazonaws.auth.AWSCredentials)15 Test (org.junit.Test)15 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)14 ClientConfiguration (com.amazonaws.ClientConfiguration)13 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)11 AmazonS3 (com.amazonaws.services.s3.AmazonS3)9 AmazonClientException (com.amazonaws.AmazonClientException)8 Regions (com.amazonaws.regions.Regions)8 SdkClientException (com.amazonaws.SdkClientException)7 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)7 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)6 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)6 File (java.io.File)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)5 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)3 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)3 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)3