List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client
@SdkInternalApi AmazonS3Client(AmazonS3ClientParams s3ClientParams)
From source file:com.miovision.oss.awsbillingtools.examples.S3BillingRecordFileScannerExampleApplication.java
License:Open Source License
protected static S3BillingRecordFileScanner createBillingRecordFileScanner(String[] args) { if (args.length < 2) { System.err.println("Invalid arguments: expected <bucketName> and <awsAccountId>"); System.exit(-1);/*from ww w .ja v a 2 s . c o m*/ } // Construct an instance of AmazonS3 (the AWS S3 client) using the default credentials provider chain. This will // use all of the usual approaches to try and find AWS credentials. The easiest approach is to define the // environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. // // For more information: // http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html AmazonS3 amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); String bucketName = args[0]; // This is the AWS account ID of the billing files and NOT the AWS credentials. They may not be the same. String awsAccountId = args[1]; // The S3 prefix for where your billing files live. String prefix = ""; if (args.length > 2) { prefix = args[2]; } return new S3BillingRecordFileScanner(amazonS3, bucketName, prefix, awsAccountId); }
From source file:com.miovision.oss.awsbillingtools.examples.S3BillingRecordLoaderExampleApplication.java
License:Open Source License
protected static S3BillingRecordLoader<DetailedLineItem> createBillingRecordLoader(String[] args) { if (args.length < 2) { System.err.println("Invalid arguments: expected <bucketName> and <awsAccountId>"); System.exit(-1);//from w w w. j a va 2 s. com } // Construct an instance of AmazonS3 (the AWS S3 client) using the default credentials provider chain. This will // use all of the usual approaches to try and find AWS credentials. The easiest approach is to define the // environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. // // For more information: // http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html AmazonS3 amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); String bucketName = args[0]; // This is the AWS account ID of the billing files and NOT the AWS credentials. They may not be the same. String awsAccountId = args[1]; // The S3 prefix for where your billing files live. String prefix = ""; if (args.length > 2) { prefix = args[2]; } S3BillingRecordFileScanner fileScanner = new S3BillingRecordFileScanner(amazonS3, bucketName, prefix, awsAccountId); DetailedLineItemParser billingRecordParser = new DetailedLineItemParser(); return new S3BillingRecordLoader<>(amazonS3, fileScanner, billingRecordParser); }
From source file:com.MobMonkey.Helpers.SimpleWorkFlow.ConfigHelper.java
License:Open Source License
public AmazonS3 createS3Client() { AWSCredentials s3AWSCredentials = new BasicAWSCredentials(this.s3AccessId, this.s3SecretKey); AmazonS3 client = new AmazonS3Client(s3AWSCredentials); return client; }
From source file:com.moxtra.S3StorageManager.java
License:Open Source License
/** * Returns a new AmazonS3 client using the default endpoint and current * credentials./* w w w. j a v a2 s . co m*/ */ public static AmazonS3Client createClient() { AWSCredentials creds = new BasicAWSCredentials(getKey(), getSecret()); //ClientConfiguration cf = new ClientConfiguration(); return new AmazonS3Client(creds); }
From source file:com.mrbjoern.blog.api.configuration.S3Configuration.java
License:Open Source License
@Bean public AmazonS3Client amazonS3Client(final AWSCredentials awsCredentials) { AmazonS3Client amazonS3Client = new AmazonS3Client(awsCredentials); return amazonS3Client; }
From source file:com.mweagle.tereus.aws.S3Resource.java
License:Open Source License
public boolean exists() { DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonS3Client awsClient = new AmazonS3Client(credentialProviderChain); try {/*from www . j av a 2s. c o m*/ awsClient.getObjectMetadata(bucketName, getS3Path()); } catch (AmazonServiceException e) { return false; } return true; }
From source file:com.mweagle.tereus.aws.S3Resource.java
License:Open Source License
@Override public void close() { if (!this.released && this.resourceURL.isPresent()) { DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonS3Client awsClient = new AmazonS3Client(credentialProviderChain); final String[] parts = this.resourceURL.get().split("/"); final String keyname = parts[parts.length - 1]; awsClient.deleteObject(bucketName, keyname); }/*w ww .j av a2 s . c o m*/ }
From source file:com.mycompany.rproject.runnableClass.java
public static void use() throws IOException { AWSCredentials awsCreds = new PropertiesCredentials( new File("/Users/paulamontojo/Desktop/AwsCredentials.properties")); AmazonSQS sqs = new AmazonSQSClient(awsCreds); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2);/*ww w. j a va 2s .c o m*/ String myQueueUrl = "https://sqs.us-west-2.amazonaws.com/711690152696/MyQueue"; System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); while (messages.isEmpty()) { messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); } String messageRecieptHandle = messages.get(0).getReceiptHandle(); String a = messages.get(0).getBody(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); //aqui opero y cuando acabe llamo para operar el siguiente. String n = ""; String dbName = "mydb"; String userName = "pmontojo"; String password = "pmontojo"; String hostname = "mydb.cued7orr1q2t.us-west-2.rds.amazonaws.com"; String port = "3306"; String jdbcUrl = "jdbc:mysql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password; Connection conn = null; Statement setupStatement = null; Statement readStatement = null; ResultSet resultSet = null; String results = ""; int numresults = 0; String statement = null; try { conn = DriverManager.getConnection(jdbcUrl); setupStatement = conn.createStatement(); String insertUrl = "select video_name from metadata where id = " + a + ";"; String checkUrl = "select url from metadata where id = " + a + ";"; ResultSet rs = setupStatement.executeQuery(insertUrl); rs.next(); System.out.println("este es el resultdo " + rs.getString(1)); String names = rs.getString(1); ResultSet ch = setupStatement.executeQuery(checkUrl); ch.next(); System.out.println("este es la url" + ch.getString(1)); String urli = ch.getString(1); while (urli == null) { ResultSet sh = setupStatement.executeQuery(checkUrl); sh.next(); System.out.println("este es la url" + sh.getString(1)); urli = sh.getString(1); } setupStatement.close(); AmazonS3 s3Client = new AmazonS3Client(awsCreds); S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, names)); IOUtils.copy(object.getObjectContent(), new FileOutputStream(new File("/Users/paulamontojo/Desktop/download.avi"))); putOutput(); write(); putInDb(sbu.toString(), a); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { System.out.println("Closing the connection."); if (conn != null) try { conn.close(); } catch (SQLException ignore) { } } use(); }
From source file:com.netflix.bdp.s3mper.cli.FileSystemVerifyCommand.java
License:Apache License
@Override public void execute(Configuration conf, String[] args) throws Exception { CmdLineParser parser = new CmdLineParser(this); String keyId = conf.get("fs.s3n.awsAccessKeyId"); String keySecret = conf.get("fs.s3n.awsSecretAccessKey"); s3 = new AmazonS3Client(new BasicAWSCredentials(keyId, keySecret)); try {/*from w w w .ja v a 2 s . c o m*/ parser.parseArgument(args); ExecutorService executor = Executors.newFixedThreadPool(threads); List<Future> futures = new ArrayList<Future>(); BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); try { for (String line = fin.readLine(); line != null; line = fin.readLine()) { futures.add(executor.submit(new FileCheckTask(new Path(line.trim())))); } } finally { fin.close(); } for (Future f : futures) { f.get(); } executor.shutdown(); } catch (CmdLineException e) { System.err.println(e.getMessage()); System.err.println("s3mper fs verify [options]"); // print the list of available options parser.printUsage(System.err); System.err.println(); System.err.println(" Example: s3mper fs verify " + parser.printExample(OptionHandlerFilter.ALL)); } }
From source file:com.netflix.dynomitemanager.sidecore.backup.S3Backup.java
License:Apache License
/** * Uses the Amazon S3 API to upload the AOF/RDB to S3 * Filename: Backup location + DC + Rack + App + Token *//*from w w w.ja v a 2 s . c o m*/ @Override public boolean upload(File file, DateTime todayStart) { logger.info("Snapshot backup: sending " + file.length() + " bytes to S3"); /* Key name is comprised of the * backupDir + DC + Rack + token + Date */ String keyName = config.getBackupLocation() + "/" + iid.getInstance().getDatacenter() + "/" + iid.getInstance().getRack() + "/" + iid.getInstance().getToken() + "/" + todayStart.getMillis(); // Get bucket location. logger.info("Key in Bucket: " + keyName); logger.info("S3 Bucket Name:" + config.getBucketName()); AmazonS3Client s3Client = new AmazonS3Client(cred.getAwsCredentialProvider()); try { // Checking if the S3 bucket exists, and if does not, then we create it if (!(s3Client.doesBucketExist(config.getBucketName()))) { logger.error("Bucket with name: " + config.getBucketName() + " does not exist"); return false; } else { logger.info("Uploading data to S3\n"); // Create a list of UploadPartResponse objects. You get one of these for // each part upload. List<PartETag> partETags = new ArrayList<PartETag>(); InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest( config.getBucketName(), keyName); InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest); long contentLength = file.length(); long filePosition = 0; long partSize = this.initPartSize; try { for (int i = 1; filePosition < contentLength; i++) { // Last part can be less than initPartSize (500MB). Adjust part size. partSize = Math.min(partSize, (contentLength - filePosition)); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(config.getBucketName()).withKey(keyName) .withUploadId(initResponse.getUploadId()).withPartNumber(i) .withFileOffset(filePosition).withFile(file).withPartSize(partSize); // Upload part and add response to our list. partETags.add(s3Client.uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest( config.getBucketName(), keyName, initResponse.getUploadId(), partETags); s3Client.completeMultipartUpload(compRequest); } catch (Exception e) { logger.error("Abosting multipart upload due to error"); s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(config.getBucketName(), keyName, initResponse.getUploadId())); } return true; } } catch (AmazonServiceException ase) { logger.error( "AmazonServiceException;" + " request made it to Amazon S3, but was rejected with an error "); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); return false; } catch (AmazonClientException ace) { logger.error("AmazonClientException;" + " the client encountered " + "an internal error while trying to " + "communicate with S3, "); logger.error("Error Message: " + ace.getMessage()); return false; } }