Example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

List of usage examples for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider.

Prototype

public AWSStaticCredentialsProvider(AWSCredentials credentials) 

Source Link

Usage

From source file:org.alanwilliamson.amazon.lambda.LambdaExecute.java

License:Open Source License

/**
 * Executes a lambda function and returns the result of the execution.
 *//*from   www.  ja  v a 2s .  c o m*/
@Override
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {

    AmazonKey amazonKey = getAmazonKey(_session, argStruct);

    // Arguments to extract
    String payload = getNamedStringParam(argStruct, "payload", null);
    String functionName = getNamedStringParam(argStruct, "function", null);
    String qualifier = getNamedStringParam(argStruct, "qualifier", null);

    try {

        // Construct the Lambda Client
        InvokeRequest invokeRequest = new InvokeRequest();
        invokeRequest.setInvocationType(InvocationType.RequestResponse);
        invokeRequest.setLogType(LogType.Tail);
        invokeRequest.setFunctionName(functionName);
        invokeRequest.setPayload(payload);
        if (qualifier != null) {
            invokeRequest.setQualifier(qualifier);
        }

        // Lambda client must be created with credentials
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(amazonKey.getKey(), amazonKey.getSecret());
        AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
                .withRegion(amazonKey.getAmazonRegion().toAWSRegion().getName())
                .withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();

        // Execute and process the results
        InvokeResult result = awsLambda.invoke(invokeRequest);

        // Convert the returned result
        ByteBuffer resultPayload = result.getPayload();
        String resultJson = new String(resultPayload.array(), "UTF-8");
        Map<String, Object> resultMap = Jackson.fromJsonString(resultJson, Map.class);

        return tagUtils.convertToCfData(resultMap);

    } catch (Exception e) {
        throwException(_session, "AmazonLambdaExecute: " + e.getMessage());
        return cfBooleanData.FALSE;
    }

}

From source file:org.apache.beam.sdk.io.aws.dynamodb.BasicDynamoDBProvider.java

License:Apache License

private AWSCredentialsProvider getCredentialsProvider() {
    return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
}

From source file:org.apache.heron.uploader.s3.S3Uploader.java

License:Apache License

@Override
public void initialize(Config config) {
    bucket = S3Context.bucket(config);
    String accessKey = S3Context.accessKey(config);
    String accessSecret = S3Context.secretKey(config);
    String awsProfile = S3Context.awsProfile(config);
    String proxy = S3Context.proxyUri(config);
    String endpoint = S3Context.uri(config);
    String customRegion = S3Context.region(config);
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

    if (Strings.isNullOrEmpty(bucket)) {
        throw new RuntimeException("Missing heron.uploader.s3.bucket config value");
    }//  w  w w.j a v  a2 s .c o  m

    // If an accessKey is specified, use it. Otherwise check if an aws profile
    // is specified. If neither was set just use the DefaultAWSCredentialsProviderChain
    // by not specifying a CredentialsProvider.
    if (!Strings.isNullOrEmpty(accessKey) || !Strings.isNullOrEmpty(accessSecret)) {

        if (!Strings.isNullOrEmpty(awsProfile)) {
            throw new RuntimeException("Please provide access_key/secret_key " + "or aws_profile, not both.");
        }

        if (Strings.isNullOrEmpty(accessKey)) {
            throw new RuntimeException("Missing heron.uploader.s3.access_key config value");
        }

        if (Strings.isNullOrEmpty(accessSecret)) {
            throw new RuntimeException("Missing heron.uploader.s3.secret_key config value");
        }
        builder.setCredentials(
                new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, accessSecret)));
    } else if (!Strings.isNullOrEmpty(awsProfile)) {
        builder.setCredentials(new ProfileCredentialsProvider(awsProfile));
    }

    if (!Strings.isNullOrEmpty(proxy)) {
        URI proxyUri;

        try {
            proxyUri = new URI(proxy);
        } catch (URISyntaxException e) {
            throw new RuntimeException("Invalid heron.uploader.s3.proxy_uri config value: " + proxy, e);
        }

        ClientConfiguration clientCfg = new ClientConfiguration();
        clientCfg.withProtocol(Protocol.HTTPS).withProxyHost(proxyUri.getHost())
                .withProxyPort(proxyUri.getPort());

        if (!Strings.isNullOrEmpty(proxyUri.getUserInfo())) {
            String[] info = proxyUri.getUserInfo().split(":", 2);
            clientCfg.setProxyUsername(info[0]);
            if (info.length > 1) {
                clientCfg.setProxyPassword(info[1]);
            }
        }

        builder.setClientConfiguration(clientCfg);
    }

    s3Client = builder.withRegion(customRegion).withPathStyleAccessEnabled(true)
            .withChunkedEncodingDisabled(true).withPayloadSigningEnabled(true).build();

    if (!Strings.isNullOrEmpty(endpoint)) {
        s3Client.setEndpoint(endpoint);
    }

    final String topologyName = Context.topologyName(config);
    final String topologyPackageLocation = Context.topologyPackageFile(config);

    pathPrefix = S3Context.pathPrefix(config);
    packageFileHandler = new File(topologyPackageLocation);

    // The path the packaged topology will be uploaded to
    remoteFilePath = generateS3Path(pathPrefix, topologyName, packageFileHandler.getName());

    // Generate the location of the backup file incase we need to revert the deploy
    previousVersionFilePath = generateS3Path(pathPrefix, topologyName,
            "previous_" + packageFileHandler.getName());
}

From source file:org.apache.metamodel.dynamodb.DynamoDbDataContextFactory.java

License:Apache License

private AWSCredentialsProvider getCredentials(DataContextProperties properties) {
    if (properties.getUsername() != null) {
        final BasicAWSCredentials credentials = new BasicAWSCredentials(properties.getUsername(),
                properties.getPassword());
        return new AWSStaticCredentialsProvider(credentials);
    } else {/*ww  w .j av  a 2s .  c  om*/
        return DefaultAWSCredentialsProviderChain.getInstance();
    }
}

From source file:org.apache.nifi.minifi.c2.cache.s3.S3ConfigurationCache.java

License:Apache License

/**
 * Creates a new S3 configuration cache.
 * @param bucket The S3 bucket.//  www  .ja v a2 s.  c o m
 * @param prefix The S3 object prefix.
 * @param pathPattern The path pattern.
 * @param accessKey The (optional) S3 access key.
 * @param secretKey The (optional) S3 secret key.
 * @param region The AWS region (e.g. us-east-1).
 * @throws IOException Thrown if the configuration cannot be read.
 */
public S3ConfigurationCache(String bucket, String prefix, String pathPattern, String accessKey,
        String secretKey, String region) throws IOException {

    this.bucket = bucket;
    this.prefix = prefix;
    this.pathPattern = pathPattern;

    if (!StringUtils.isEmpty(accessKey)) {

        s3 = AmazonS3Client.builder()
                .withCredentials(
                        new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
                .withRegion(Regions.fromName(region)).build();

    } else {

        s3 = AmazonS3Client.builder().withRegion(Regions.fromName(region)).build();
    }

}

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

License:Apache License

@Override
@Deprecated/*from w ww.ja va 2  s.c o m*/
protected GenericApiGatewayClient createClient(final ProcessContext context, final AWSCredentials credentials,
        final ClientConfiguration clientConfiguration) {
    return createClient(context, new AWSStaticCredentialsProvider(credentials), clientConfiguration);
}

From source file:org.codice.ddf.catalog.plugin.metacard.backup.storage.s3storage.MetacardS3StorageRoute.java

License:Open Source License

private AmazonS3 getS3Client() {
    AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
            s3Endpoint, getS3Region());
    if (StringUtils.isNotBlank(s3AccessKey)) {
        AWSCredentials awsCredentials = new BasicAWSCredentials(s3AccessKey, s3SecretKey);
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
        return AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider)
                .withEndpointConfiguration(endpointConfiguration).build();
    }//from  www. ja v  a 2 s  .  co m
    return AmazonS3ClientBuilder.standard().withEndpointConfiguration(endpointConfiguration).build();
}

From source file:org.datacleaner.connection.DynamoDbDatastore.java

License:Open Source License

@Override
protected UsageAwareDatastoreConnection<DynamoDbDataContext> createDatastoreConnection() {
    final AmazonDynamoDBClientBuilder clientBuilder = AmazonDynamoDBClientBuilder.standard();
    if (!Strings.isNullOrEmpty(_region)) {
        clientBuilder.setRegion(_region);
    }/*  ww  w.  java  2s . c  om*/
    final AWSCredentialsProvider credentialsProvider;
    if (!Strings.isNullOrEmpty(_accessKeyId)) {
        credentialsProvider = new AWSStaticCredentialsProvider(
                new BasicAWSCredentials(_accessKeyId, _secretAccessKey));
    } else {
        credentialsProvider = DefaultAWSCredentialsProviderChain.getInstance();
    }
    clientBuilder.setCredentials(credentialsProvider);
    final AmazonDynamoDB client = clientBuilder.build();
    final DynamoDbDataContext dataContext = new DynamoDbDataContext(client, _tableDefs);
    return new UpdateableDatastoreConnectionImpl<>(dataContext, this);
}

From source file:org.deeplearning4j.legacyExamples.EmrSparkExample.java

License:Apache License

public AWSStaticCredentialsProvider getCredentialsProvider() {
    return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
}

From source file:org.duracloud.integration.durastore.storage.probe.ProbedRestS3Client.java

License:Apache License

public ProbedRestS3Client(BasicAWSCredentials credentials) throws AmazonServiceException {
    this.s3Client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
}