use of com.amazonaws.auth.AWSStaticCredentialsProvider in project beam by apache.
the class AwsSerializableUtilsTest method testBasicCredentialsProviderSerialization.
@Test
public void testBasicCredentialsProviderSerialization() {
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
String serializedProvider = serialize(credentialsProvider);
checkStaticBasicCredentials(deserialize(serializedProvider));
}
use of com.amazonaws.auth.AWSStaticCredentialsProvider in project beam by apache.
the class S3FileSystemTest method beforeClass.
@BeforeClass
public static void beforeClass() {
api = new S3Mock.Builder().withInMemoryBackend().build();
Http.ServerBinding binding = api.start();
EndpointConfiguration endpoint = new EndpointConfiguration("http://localhost:" + binding.localAddress().getPort(), "us-west-2");
client = AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
}
use of com.amazonaws.auth.AWSStaticCredentialsProvider in project heron by twitter.
the class S3Uploader method initialize.
@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");
}
// 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());
}
use of com.amazonaws.auth.AWSStaticCredentialsProvider in project bayou by capergroup.
the class S3LoggerBase method putToS3.
/**
* Performs an S3 Put Object operation storing the UTF-8 bytes of logMsg under the given key
* using construction provided AWS credentials.
*
* @param objectKey the S3 object key. may not be null or whitespace only.
* @param logMsg the message to store
* @throws IllegalArgumentException if objectKey is whitespace only.
*/
void putToS3(String objectKey, String logMsg) {
if (objectKey == null)
throw new NullPointerException("objectKey");
if (objectKey.trim().length() == 0)
throw new IllegalArgumentException("objectKey may not be only whitespace.");
/*
* Make the client used to send the log msg to S3.
*/
AmazonS3 client;
{
Regions regions = Regions.US_EAST_1;
if (_credentials == null) {
client = // get creds from environment
AmazonS3ClientBuilder.standard().withRegion(regions).build();
} else {
client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(_credentials)).withRegion(regions).build();
}
}
/*
* Store the log msg in S3.
*/
byte[] logMsgBytes = logMsg.getBytes(StandardCharsets.UTF_8);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(logMsgBytes.length);
client.putObject(_bucketName, objectKey, new ByteArrayInputStream(logMsgBytes), metadata);
_logger.debug("exiting");
}
use of com.amazonaws.auth.AWSStaticCredentialsProvider in project carbon-apimgt by wso2.
the class AWSLambdaMediator method invokeLambda.
/**
* invoke AWS Lambda function
*
* @param payload - input parameters to pass to AWS Lambda function as a JSONString
* @return InvokeResult
*/
private InvokeResult invokeLambda(String payload) {
try {
// set credential provider
AWSCredentialsProvider credentialsProvider;
AWSLambda awsLambda;
if (StringUtils.isEmpty(accessKey) && StringUtils.isEmpty(secretKey)) {
if (log.isDebugEnabled()) {
log.debug("Using temporary credentials supplied by the IAM role attached to the EC2 instance");
}
credentialsProvider = DefaultAWSCredentialsProviderChain.getInstance();
awsLambda = AWSLambdaClientBuilder.standard().withCredentials(credentialsProvider).build();
} else if (!StringUtils.isEmpty(accessKey) && !StringUtils.isEmpty(secretKey) && !StringUtils.isEmpty(region)) {
if (log.isDebugEnabled()) {
log.debug("Using user given stored credentials");
}
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
credentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
awsLambda = AWSLambdaClientBuilder.standard().withCredentials(credentialsProvider).withRegion(region).build();
} else {
log.error("Missing AWS Credentials");
return null;
}
// set invoke request
if (resourceTimeout < 1000 || resourceTimeout > 900000) {
setResourceTimeout(APIConstants.AWS_DEFAULT_CONNECTION_TIMEOUT);
}
InvokeRequest invokeRequest = new InvokeRequest().withFunctionName(resourceName).withPayload(payload).withInvocationType(InvocationType.RequestResponse).withSdkClientExecutionTimeout(resourceTimeout);
return awsLambda.invoke(invokeRequest);
} catch (SdkClientException e) {
log.error("Error while invoking the lambda function", e);
}
return null;
}
Aggregations