List of usage examples for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider
public AWSStaticCredentialsProvider(AWSCredentials credentials)
From source file:io.macgyver.plugin.cloud.aws.AWSServiceFactory.java
License:Apache License
private AWSCredentialsProvider getCredentialsProvider(ServiceDefinition def) { String accessKey = def.getProperty("accessKey"); String secretKey = def.getProperty("secretKey"); if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) { logger.info("using static credentials " + accessKey + " for AWS service " + def.getName()); return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); }/*from www .jav a 2 s. c om*/ String sourceService = def.getProperty("sourceService"); String assumeRoleName = def.getProperty("assumeRoleName"); if (!StringUtils.isNullOrEmpty(sourceService) && !StringUtils.isNullOrEmpty(assumeRoleName)) { String roleArn = "arn:aws:iam::" + def.getProperty("accountId") + ":role/" + assumeRoleName; logger.info("using assume-role credentials for " + roleArn + " from " + sourceService + " for AWS service " + def.getName()); return new AWSServiceClientAssumeRoleCredentialsProvider(registry, sourceService, roleArn); } logger.info("using default credentials provider for AWS service " + def.getName()); return new DefaultAWSCredentialsProviderChain(); }
From source file:io.prestosql.plugin.hive.s3.PrestoS3FileSystem.java
License:Apache License
private AWSCredentialsProvider createAwsCredentialsProvider(URI uri, Configuration conf) { Optional<AWSCredentials> credentials = getAwsCredentials(uri, conf); if (credentials.isPresent()) { return new AWSStaticCredentialsProvider(credentials.get()); }// w w w . j av a2s . co m if (useInstanceCredentials) { return InstanceProfileCredentialsProvider.getInstance(); } String providerClass = conf.get(S3_CREDENTIALS_PROVIDER); if (!isNullOrEmpty(providerClass)) { return getCustomAWSCredentialsProvider(uri, conf, providerClass); } throw new RuntimeException("S3 credentials not configured"); }
From source file:mx.iteso.desi.cloud.hw3.AWSFaceCompare.java
License:Apache License
public AWSFaceCompare(String accessKey, String secretKey, Regions region, String srcBucket) { this.srcBucket = srcBucket; this.accessKey = accessKey; this.secretKey = secretKey; this.region = region; AWSCredentialsProvider credProvider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(accessKey, secretKey)); arek = AmazonRekognitionClientBuilder.standard().withCredentials(credProvider).withRegion(region).build(); s3 = AmazonS3ClientBuilder.standard().withCredentials(credProvider).withRegion(region).build(); }
From source file:mx.iteso.desi.cloud.hw3.FaceAddFrame.java
License:Apache License
public FaceAddFrame() { BasicAWSCredentials cred = new BasicAWSCredentials(Config.accessKeyID, Config.secretAccessKey); this.webCam = new WebCamStream(Config.CAMERA); initComponents();// w w w . java 2 s .c o m this.s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(cred)) .withRegion(Config.amazonRegion).build(); // Center this.setLocationRelativeTo(null); }
From source file:mx.iteso.desi.cloud.keyvalue.DynamoDBStorage.java
License:Apache License
public DynamoDBStorage(String dbName) { BasicAWSCredentials cred = new BasicAWSCredentials(Config.accessKeyID, Config.secretAccessKey); if (Config.DynamoDbClientType == Config.DYNAMODBCLIENTTYPE.Local) { client = new AmazonDynamoDBClient(cred); client.setRegion(Region.getRegion(Config.amazonRegion)); client.setEndpoint("http://localhost:8000"); } else {//from w w w.ja va2 s .c o m client = AmazonDynamoDBClientBuilder.standard().withRegion(Config.amazonRegion) .withCredentials(new AWSStaticCredentialsProvider(cred)).build(); } docClient = new DynamoDB(client); this.dbName = dbName; // Create a table CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(dbName) .withKeySchema(new KeySchemaElement().withAttributeName("keyword").withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName("inx").withKeyType(KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName("keyword") .withAttributeType(ScalarAttributeType.S), new AttributeDefinition().withAttributeName("inx").withAttributeType(ScalarAttributeType.N)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(client, createTableRequest); // Wait for the table to move into Active state try { TableUtils.waitUntilActive(client, dbName); } catch (Exception e) { // Do nothing... yet } //requestItems.put(dbName, requestList); }
From source file:net.solarnetwork.node.backup.s3.S3BackupService.java
License:Open Source License
private void setupClient() { SdkS3Client c = s3Client;/* ww w . jav a 2 s . c o m*/ if (c != null) { c.setBucketName(bucketName); c.setRegionName(regionName); if (accessToken != null && accessToken.length() > 0 && accessSecret != null && accessSecret.length() > 0) { c.setCredentialsProvider( new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessToken, accessSecret))); } if (c.isConfigured()) { status.set(BackupStatus.Configured); } } }
From source file:nl.kpmg.lcm.server.data.s3.S3FileAdapter.java
License:Apache License
public S3FileAdapter(S3FileStorage s3Storage, String fileName) { String secretAcccessKey;/*from www.j a va 2s . c o m*/ secretAcccessKey = s3Storage.getAwsSecretAccessKey(); AWSCredentials credentials = new BasicAWSCredentials(s3Storage.getAwsAccessKey(), secretAcccessKey); AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider) .withRegion(Regions.EU_WEST_1).build(); bucketName = s3Storage.getBucketName(); if (fileName.charAt(0) == '/') { // amazon s3 service don't like "/" in front of the file name this.fileName = fileName.substring(1); } else { this.fileName = fileName; } object = s3Client.getObject(new GetObjectRequest(bucketName, fileName)); }
From source file:nl.kpmg.lcm.server.data.s3.S3FileSystemAdapter.java
License:Apache License
public S3FileSystemAdapter(S3FileStorage s3Storage) { String secretAcccessKey;//from w w w.ja v a2 s.com secretAcccessKey = s3Storage.getAwsSecretAccessKey(); AWSCredentials credentials = new BasicAWSCredentials(s3Storage.getAwsAccessKey(), secretAcccessKey); AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider) .withRegion(Regions.EU_WEST_1).build(); bucketName = s3Storage.getBucketName(); }
From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java
License:Apache License
@Override public void open() { CredentialFactory cf = new CredentialFactory(getAuthAlias(), getAccessKey(), getSecretKey()); BasicAWSCredentials awsCreds = new BasicAWSCredentials(cf.getUsername(), cf.getPassword()); AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard() .withChunkedEncodingDisabled(isChunkedEncodingDisabled()) .withForceGlobalBucketAccessEnabled(isForceGlobalBucketAccessEnabled()) .withRegion(getClientRegion()).withCredentials(new AWSStaticCredentialsProvider(awsCreds)); s3Client = s3ClientBuilder.build();/*w ww .j av a 2s .com*/ }
From source file:org.alanwilliamson.amazon.lambda.LambdaAsyncExecute.java
License:Open Source License
/** * Executes a lambda function and returns the result of the execution. *//* w ww. j a v a 2 s . c om*/ @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.Event); 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 awsLambda.invoke(invokeRequest); } catch (Exception e) { throwException(_session, "AmazonLambdaAsyncExecute: " + e.getMessage()); return cfBooleanData.FALSE; } return cfBooleanData.TRUE; }