Example usage for com.amazonaws.regions Region getRegion

List of usage examples for com.amazonaws.regions Region getRegion

Introduction

In this page you can find the example usage for com.amazonaws.regions Region getRegion.

Prototype

public static Region getRegion(Regions region) 

Source Link

Document

Returns the region with the id given, or null if it cannot be found in the current regions.xml file.

Usage

From source file:io.macgyver.plugin.cloud.aws.scanner.AWSServiceScanner.java

License:Apache License

public void scanAllRegions() {
    for (Regions r : Regions.values()) {
        try {//  w w w.  ja va 2  s  .c  o m
            scan(Region.getRegion(r));
        } catch (RuntimeException e) {
            logger.warn("regions", e);
        }
    }
}

From source file:io.macgyver.plugin.cloud.aws.scanner.AWSServiceScanner.java

License:Apache License

public void scan(String region) {

    scan(Region.getRegion(Regions.fromName(region)));
}

From source file:io.macgyver.plugin.cloud.aws.scanner.DefaultAWSScannerGroup.java

License:Apache License

public static void main(String[] args) throws Exception {

    AWSServiceClientImpl c = new AWSServiceClientImpl(new DefaultAWSCredentialsProviderChain(), "000000000000");

    NeoRxClient neo4j = new NeoRxClientBuilder().build();

    AWSScannerGroup g = new DefaultAWSScannerGroup(c, neo4j);

    g.scan(Region.getRegion(Regions.US_WEST_2));
}

From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.InfrastructureConfiguration.java

License:Apache License

@Bean
@ConditionalOnProperty("aws.accessKeyId")
AmazonEC2Client amazonEC2(@Value("${aws.accessKeyId}") String accessKeyId,
        @Value("${aws.secretAccessKey}") String secretAccessKey,
        @Value("${aws.region:us-east-1}") String regionName) {

    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(
            new BasicAWSCredentials(accessKeyId, secretAccessKey));
    Region region = Region.getRegion(Regions.fromName(regionName));
    amazonEC2Client.setEndpoint(region.getServiceEndpoint("ec2"));

    return amazonEC2Client;
}

From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
//   * @see com.amazonaws.auth.ProfilesConfigFile
 * @see com.amazonaws.ClientConfiguration
 *///from w ww.  ja va2s. c  o  m

public static void init() {
    if (initialized)
        return;

    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (C:\\Users\\Robert\\.aws\\credentials).
     */

    AWSCredentials credentials;
    try {
        credentials = new BasicAWSCredentials(accessKey, secretKey);
    } 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 (C:\\Users\\Robert\\.aws\\credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(usEast1);

    initialized = true;
}

From source file:Java21.S3Files.java

License:Open Source License

public static void main(String[] args) throws IOException {

    /*/*from w ww  .java 2s .c  o m*/
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (~/.aws/credentials).
     */
    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 usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

    String bucketName = "msm-gb-env-etl-iq/dev1-dwh/" + UUID.randomUUID();
    //String key = "";

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon S3");
    System.out.println("===========================================\n");

    /*
     * List objects in your bucket by prefix - There are many options for
     * listing the objects in your bucket.  Keep in mind that buckets with
     * many objects might truncate their results when listing their objects,
     * so be sure to check if the returned object listing is truncated, and
     * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
     * additional results.
     */
    System.out.println("Listing objects");
    ObjectListing objectListing = s3
            .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My"));
    for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        System.out.println(" - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
    }
    System.out.println();

}

From source file:javafxawss3sample.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    AmazonS3 s3 = new AmazonS3Client();
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);/* w w w.j a  v a2  s. com*/
    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon S3");
    System.out.println("===========================================");
    s3.listBuckets().forEach(bucket -> {
        // creating tab for each bucket
        Tab tab = new Tab();
        String bucketNm = bucket.getName();
        tab.setText(bucketNm);
        tabPane.getTabs().add(tab);
        VBox vbox = new VBox(10);
        vbox.setPadding(new Insets(10));
        vbox.setStyle("-fx-background-color: #ffc9ae");
        // Owner
        HBox hbox1 = new HBox(10);
        Label ownerLabel = new Label("Owner:");
        String owner = bucket.getOwner().getDisplayName();
        Text ownerText = new Text(owner);
        hbox1.getChildren().addAll(ownerLabel, ownerText);
        // Create Date
        HBox hbox2 = new HBox(10);
        Label dateLabel = new Label("Create Date:");
        String createDate = bucket.getCreationDate().toString();
        Text dateText = new Text(createDate);
        hbox2.getChildren().addAll(dateLabel, dateText);
        tab.setContent(vbox);
        tab.setStyle("-fx-background-color: #ffc9ae;");
        // ListView for file path
        ObservableList<String> items = FXCollections.observableArrayList("file path");
        ListView view = new ListView(items);
        ObjectListing objList = s3
                .listObjects(new ListObjectsRequest().withBucketName(bucketNm).withPrefix(""));
        objList.getObjectSummaries().forEach(obj -> {
            String filePath = obj.getKey();
            items.add(filePath);
        });
        vbox.getChildren().addAll(hbox1, hbox2, view);
    });
}

From source file:jetbrains.buildServer.runner.cloudformation.AWSClient.java

License:Apache License

/**
 * Uploads application revision archive to S3 bucket named s3BucketName with
 * the provided key and bundle type.//from www.jav  a  2 s  .co m
 * <p>
 * For performing this operation target AWSClient must have corresponding S3
 * permissions.
 *
 * @param s3BucketName
 *            valid S3 bucket name
 * @param s3ObjectKey
 *            valid S3 object key
 */
public void initiateCFN(@NotNull String stackName, @NotNull String region, @NotNull String s3BucketName,
        @NotNull String s3ObjectKey, @NotNull String cfnAction, @NotNull String onFailure) {
    try {
        String templateURL;
        Region reg = Region.getRegion(Regions.fromName(region));
        myCloudFormationClient.setRegion(reg);
        templateURL = getTemplateUrl(reg, s3BucketName, s3ObjectKey);
        System.out.println("The template url is " + templateURL);

        if (cfnAction.equalsIgnoreCase("Create")) {
            System.out.println("The CFN action is " + cfnAction);
            myListener.createStackStarted(stackName, region, s3BucketName, s3ObjectKey, cfnAction);
            CreateStackRequest createRequest = new CreateStackRequest();
            createRequest.setStackName(stackName);
            if (!onFailure.equalsIgnoreCase("null"))
                createRequest.setOnFailure(onFailure);
            createRequest.setTemplateURL(templateURL);
            myCloudFormationClient.createStack(createRequest);
            waitForCompletion(myCloudFormationClient, stackName);

        } else if (cfnAction.equalsIgnoreCase("Delete")) {
            myListener.deleteStarted(stackName, region);
            DeleteStackRequest deleteStackRequest = new DeleteStackRequest();
            deleteStackRequest.setStackName(stackName);
            myCloudFormationClient.deleteStack(deleteStackRequest);
            waitForDelete(myCloudFormationClient, stackName);

        } else if (cfnAction.equalsIgnoreCase("Validate")) {
            myListener.validateStarted(stackName);
            ValidateTemplateRequest validatetempRequest = new ValidateTemplateRequest();
            validatetempRequest.setTemplateURL(templateURL);
            myListener.validateFinished(
                    myCloudFormationClient.validateTemplate(validatetempRequest).getParameters().toString());

        } else if (cfnAction.equalsIgnoreCase("Update")) {
            myListener.updateInProgress(stackName);
            UpdateStackRequest updateStackRequest = new UpdateStackRequest();
            updateStackRequest.setStackName(stackName);
            updateStackRequest.setTemplateURL(templateURL);
            myCloudFormationClient.updateStack(updateStackRequest);
            waitForCompletion(myCloudFormationClient, stackName);
        }
    } catch (Throwable t) {
        processFailure(t);
    }
}

From source file:jetbrains.buildServer.util.amazon.AWSRegions.java

License:Apache License

@NotNull
public static Region getRegion(@NotNull String regionName) throws IllegalArgumentException {
    try {//from w w w . jav a2  s  .com
        return Region.getRegion(Regions.fromName(regionName));
    } catch (Exception e) {
        // see below
    }
    throw new IllegalArgumentException("Unsupported region name " + regionName);
}

From source file:jp.classmethod.aws.RegionFactoryBean.java

License:Apache License

@Override
public Region getObject() {
    Regions region = defaultRegion;//from  ww  w.  j a v  a2s.  c om
    for (Regions r : Regions.values()) {
        if (r.getName().equals(metadata.getRegion())) {
            region = r;
            break;
        }
    }

    Region bean = Region.getRegion(region);
    logger.info("loaded {}", bean);
    return bean;
}