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());
}
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());
}
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);
}
}
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);
}
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[]
}
Aggregations