use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class AWSStatusCheck method init.
private static void init() throws Exception {
AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
ec2 = new AmazonEC2Client(credentials);
s3 = new AmazonS3Client(credentials);
sdb = new AmazonSimpleDBClient(credentials);
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class AWSEC2 method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream(System.getProperty("user.home") + FILESEPARATOR + ".aws" + FILESEPARATOR + "credentials"));
//Create Amazon Client object
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
RegionRecord region = RegionRecord.US_EAST_1;
String keyName = "aws";
String installScript = "#!/bin/bash\n" + "cd /home/ec2-user\n" + "yum --quiet --assumeyes update\n";
HashMap<String, String> tags = new HashMap<>();
tags.put("runset", new Date().toString());
createAndInitInstance(ec2, region, AMIRecord.getAMI(AMIRecordType.Amazon_Linux_AMI_2013_03_1, region), "Test Instance", keyName, DEFAULT_SECURITY_GROUP_NAME, installScript, tags, "23.21.120.250");
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class EC2Runner method terminateRunSet.
/**
* Terminates all the hosts in the named run set.
*
* @param name
*/
public static void terminateRunSet(String name) {
try {
AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
//Create Amazon Client object
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
for (RegionRecord region : RegionRecord.values()) {
AWSEC2.setRegion(ec2, region);
for (Instance instance : AWSEC2.getInstances(ec2)) {
if (!instance.getState().getName().equals(InstanceStateRecord.TERMINATED.getName())) {
String idString = getTagValue(instance, "id");
if (name.equals(getTagValue(instance, "runset"))) {
if (idString != null) {
// StatusModel.getInstance().queueUpdate(new String(idString), "Terminating");
}
AWSEC2.terminateInstance(ec2, instance.getInstanceId());
if (idString != null) {
// StatusModel.getInstance().queueUpdate(new String(idString), StatusEntry.State.TERMINATED, "");
}
}
}
}
}
} catch (IOException e) {
System.out.println("Problem terminating EC2 instances: " + e);
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.println("Problem terminating EC2 instances: " + e);
e.printStackTrace();
}
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class EC2Runner method populateIDTableForRunset.
private static void populateIDTableForRunset(String name) {
AWSCredentials credentials = null;
try {
//
credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
} catch (IOException e) {
System.out.println("Problem contacting EC2 instances: " + e);
}
//Create Amazon Client object
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
for (RegionRecord region : RegionRecord.values()) {
AWSEC2.setRegion(ec2, region);
System.out.println("Retrieving instance information in " + region.name() + "...");
for (Instance instance : AWSEC2.getInstances(ec2)) {
if (!instance.getState().getName().equals(InstanceStateRecord.TERMINATED.getName())) {
String idString = getTagValue(instance, "id");
if (idString != null && name.equals(getTagValue(instance, "runset"))) {
String id = new String(idString);
String hostname = instance.getPublicDnsName();
String ip = getHostIPSafe(hostname);
// and take a guess at the location (lat, long) of this host
Point2D location = GEOLocator.lookupIPLocation(ip);
hostTable.put(id, new HostInfo(id, hostname, location));
}
}
}
}
}
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);
}
}
}
Aggregations