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:org.apache.apex.malhar.lib.fs.s3.S3Reconciler.java

License:Apache License

@Override
public void setup(Context.OperatorContext context) {
    s3client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
    if (region != null) {
        s3client.setRegion(Region.getRegion(Regions.fromName(region)));
    }//from   www. ja  va2s .  c  om
    filePath = context.getValue(DAG.APPLICATION_PATH);
    try {
        fs = FileSystem.newInstance(new Path(filePath).toUri(), new Configuration());
    } catch (IOException e) {
        logger.error("Unable to create FileSystem: {}", e.getMessage());
    }
    super.setup(context);
}

From source file:org.apache.flink.streaming.connectors.kinesis.proxy.DynamoDBStreamsProxy.java

License:Apache License

/**
 * Creates an AmazonDynamoDBStreamsAdapterClient.
 * Uses it as the internal client interacting with the DynamoDB streams.
 *
 * @param configProps configuration properties
 * @return an AWS DynamoDB streams adapter client
 *///from w  ww  . j a va  2  s. c  o  m
@Override
protected AmazonKinesis createKinesisClient(Properties configProps) {
    ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig();
    setAwsClientConfigProperties(awsClientConfig, configProps);

    AWSCredentialsProvider credentials = getCredentialsProvider(configProps);
    awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT, EnvironmentInformation.getVersion(),
            EnvironmentInformation.getRevisionInformation().commitId));

    AmazonDynamoDBStreamsAdapterClient adapterClient = new AmazonDynamoDBStreamsAdapterClient(credentials,
            awsClientConfig);

    if (configProps.containsKey(AWS_ENDPOINT)) {
        adapterClient.setEndpoint(configProps.getProperty(AWS_ENDPOINT));
    } else {
        adapterClient.setRegion(Region.getRegion(Regions.fromName(configProps.getProperty(AWS_REGION))));
    }

    return adapterClient;
}

From source file:org.apache.flink.streaming.connectors.kinesis.util.AWSUtil.java

License:Apache License

/**
 * Creates an Amazon Kinesis Client.//  w  w  w.j a  va  2s  . co  m
 * @param configProps configuration properties containing the access key, secret key, and region
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesisClient createKinesisClient(Properties configProps) {
    // set a Flink-specific user agent
    ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig();
    awsClientConfig.setUserAgent("Apache Flink " + EnvironmentInformation.getVersion() + " ("
            + EnvironmentInformation.getRevisionInformation().commitId + ") Kinesis Connector");

    // utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider
    AmazonKinesisClient client = new AmazonKinesisClient(AWSUtil.getCredentialsProvider(configProps),
            awsClientConfig);

    client.setRegion(
            Region.getRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION))));
    if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
        client.setEndpoint(configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT));
    }
    return client;
}

From source file:org.apache.hadoop.metrics.cloudwatch.CloudWatchContext.java

License:Apache License

@Override
public void init(String contextName, ContextFactory factory) {
    super.init(contextName, factory);

    String accessKey = getAttribute("accesskey");
    String secretKey = getAttribute("secretkey");
    String region = getAttribute("region");
    String namespace = getAttribute("namespace");

    try {/*from  ww w .java 2  s .  com*/
        _namespace = (null == namespace ? "Custom" : namespace);

        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
        _client = new AmazonCloudWatchClient(awsCredentials);
        _client.setRegion(Region.getRegion(Regions.fromName(region)));
    } catch (Exception e) {
        throw new MetricsException(e.getMessage());
    }
}

From source file:org.apache.hadoop.metrics2.cloudwatch.CloudWatchSink.java

License:Apache License

@Override
public void init(SubsetConfiguration conf) {
    String accessKey = conf.getString("accesskey");
    String secretKey = conf.getString("secretkey");
    String region = conf.getString("region");
    String namespace = conf.getString("namespace");
    String batch = conf.getString("batch");

    try {/*w  w w .  ja  v  a  2  s  .  c  o m*/
        _namespace = (null == namespace ? "Custom" : namespace);
        _batch = (null == batch ? 5 : Integer.valueOf(batch));

        AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
        _client = new AmazonCloudWatchClient(awsCredentials);
        _client.setRegion(Region.getRegion(Regions.fromName(region)));
    } catch (Exception e) {
        throw new MetricsException(e.getMessage());
    }
}

From source file:org.apache.nifi.processors.aws.AbstractAWSProcessor.java

License:Apache License

protected void initializeRegionAndEndpoint(ProcessContext context) {
    // if the processor supports REGION, get the configured region.
    if (getSupportedPropertyDescriptors().contains(REGION)) {
        final String region = context.getProperty(REGION).getValue();
        if (region != null) {
            this.region = Region.getRegion(Regions.fromName(region));
            client.setRegion(this.region);
        } else {/*from w ww .java2s. c  om*/
            this.region = null;
        }
    }

    // if the endpoint override has been configured, set the endpoint.
    // (per Amazon docs this should only be configured at client creation)
    if (getSupportedPropertyDescriptors().contains(ENDPOINT_OVERRIDE)) {
        final String urlstr = StringUtils
                .trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue());
        if (!urlstr.isEmpty()) {
            getLogger().info("Overriding endpoint with {}", new Object[] { urlstr });
            this.client.setEndpoint(urlstr);
        }
    }
}

From source file:org.apache.nifi.processors.aws.s3.encryption.ClientSideCMKEncryptionStrategy.java

License:Apache License

/**
 * Create an encryption client./*from   ww  w.  j  a  va 2 s  . c o  m*/
 *
 * @param credentialsProvider AWS credentials provider.
 * @param clientConfiguration Client configuration
 * @param region AWS region
 * @param keyIdOrMaterial client master key, always base64 encoded
 * @return AWS S3 client
 */
@Override
public AmazonS3Client createEncryptionClient(AWSCredentialsProvider credentialsProvider,
        ClientConfiguration clientConfiguration, String region, String keyIdOrMaterial)
        throws SecurityException {
    if (!validateKey(keyIdOrMaterial).isValid()) {
        throw new SecurityException("Invalid client key; ensure key material is base64 encoded.");
    }

    byte[] keyMaterial = Base64.decodeBase64(keyIdOrMaterial);
    SecretKeySpec symmetricKey = new SecretKeySpec(keyMaterial, "AES");
    StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(
            new EncryptionMaterials(symmetricKey));
    boolean haveRegion = StringUtils.isNotBlank(region);
    CryptoConfiguration cryptoConfig = new CryptoConfiguration();
    Region awsRegion = null;

    if (haveRegion) {
        awsRegion = Region.getRegion(Regions.fromName(region));
        cryptoConfig.setAwsKmsRegion(awsRegion);
    }

    AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(credentialsProvider,
            encryptionMaterialsProvider, cryptoConfig);
    if (haveRegion && awsRegion != null) {
        client.setRegion(awsRegion);
    }

    return client;
}

From source file:org.apache.nifi.processors.aws.s3.encryption.ClientSideKMSEncryptionStrategy.java

License:Apache License

/**
 * Create an encryption client.//from   w  ww  .java  2 s .  c  o m
 *
 * @param credentialsProvider AWS credentials provider.
 * @param clientConfiguration Client configuration
 * @param region AWS region
 * @param keyIdOrMaterial KMS key id
 * @return AWS S3 client
 */
@Override
public AmazonS3Client createEncryptionClient(AWSCredentialsProvider credentialsProvider,
        ClientConfiguration clientConfiguration, String region, String keyIdOrMaterial) {
    KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(keyIdOrMaterial);
    boolean haveRegion = StringUtils.isNotBlank(region);
    Region awsRegion = null;

    CryptoConfiguration cryptoConfig = new CryptoConfiguration();
    if (haveRegion) {
        awsRegion = Region.getRegion(Regions.fromName(region));
        cryptoConfig.setAwsKmsRegion(awsRegion);
    }

    AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(credentialsProvider, materialProvider,
            cryptoConfig);
    if (haveRegion) {
        client.setRegion(awsRegion);
    }

    return client;
}

From source file:org.apache.nifi.processors.aws.s3.encryption.service.StandardS3ClientSideEncryptionService.java

License:Apache License

private CryptoConfiguration cryptoConfiguration() {
    CryptoConfiguration config = new CryptoConfiguration();

    if (!StringUtils.isBlank(cryptoMode)) {
        config.setCryptoMode(CryptoMode.valueOf(cryptoMode));
    }//from   w  w  w . j a v a  2  s.c om

    if (!StringUtils.isBlank(cryptoStorageMode)) {
        config.setStorageMode(CryptoStorageMode.valueOf(cryptoStorageMode));
    }

    if (!StringUtils.isBlank(kmsRegion)) {
        config.setAwsKmsRegion(Region.getRegion(Regions.fromName(kmsRegion)));
    }

    config.setIgnoreMissingInstructionFile(ignoreMissingInstructionFile);
    return config;
}

From source file:org.apache.nifi.processors.aws.wag.AbstractAWSGatewayApiProcessor.java

License:Apache License

@Override
protected GenericApiGatewayClient createClient(ProcessContext context,
        AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) {

    GenericApiGatewayClientBuilder builder = new GenericApiGatewayClientBuilder()
            .withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration)
            .withEndpoint(context.getProperty(PROP_AWS_GATEWAY_API_ENDPOINT).getValue()).withRegion(Region
                    .getRegion(Regions.fromName(context.getProperty(PROP_AWS_GATEWAY_API_REGION).getValue())));
    if (context.getProperty(PROP_AWS_API_KEY).isSet()) {
        builder = builder/* w  ww  . j a  v a2  s  . c  o  m*/
                .withApiKey(context.getProperty(PROP_AWS_API_KEY).evaluateAttributeExpressions().getValue());
    }
    if (providedClient != null) {
        builder = builder.withHttpClient(providedClient);
    }
    return builder.build();
}