List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client
@SdkInternalApi AmazonS3Client(AmazonS3ClientParams s3ClientParams)
From source file:com.conductor.s3.S3HadoopUtils.java
License:Apache License
/** * Extracts the AWS key and secret from the conf, and returns a new S3 client. * //w ww . j a va 2 s.c om * @param conf * job conf * @return an S3 client. * @throws java.lang.IllegalArgumentException * if it cannot find key/id in the conf. */ public static AmazonS3 getS3Client(final Configuration conf) { final String accessKey = conf.get("fs.s3n.awsAccessKeyId", conf.get("fs.s3.awsAccessKeyId")); checkArgument(!Strings.isNullOrEmpty(accessKey), "Missing fs.s3/n.awsAccessKeyId conf."); final String secretKey = conf.get("fs.s3n.awsSecretAccessKey", conf.get("fs.s3.awsSecretAccessKey")); checkArgument(!Strings.isNullOrEmpty(secretKey), "Missing fs.s3/n.awsSecretAccessKey conf."); return new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); }
From source file:com.crickdata.upload.s3.UploadLiveData.java
License:Open Source License
public Map<String, Date> uploadToS3(String fileName, boolean type) throws IOException { Statistics statistics = new Statistics(); Map<String, Date> perfMap = new HashMap<String, Date>(); AWSCredentials credentials = null;// w ww. j av a2 s.c o m try { credentials = new BasicAWSCredentials("AKIAI6QKTRAQE7MXQOIQ", "wIG6u1yI5ZaseeJbvYSUmD98qelIJNSCVBzt5k2q"); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (C:\\Users\\bssan_000\\.aws\\credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); String bucketName; if (!type) bucketName = "cricmatchinfo"; else bucketName = "cricmatchinfoseries"; String key = fileName.replace(".json", "").trim(); try { perfMap.put("S3INSERTREQ", new Date()); statistics.setS3Req(new Date()); File f = readMatchFile(fileName); double bytes = f.length(); double kilobytes = (bytes / 1024); System.out.println("Details :" + kilobytes); s3.putObject(new PutObjectRequest(bucketName, key, f)); statistics.setSize(String.valueOf(kilobytes)); S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); perfMap.put("S3SAVERES", object.getObjectMetadata().getLastModified()); statistics.setKey(key); statistics.setS3Res(object.getObjectMetadata().getLastModified()); MyUI.stats.add(statistics); displayTextInputStream(object.getObjectContent()); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println( " - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } return perfMap; }
From source file:com.dannyofir.www.overdarevideorecorder.MainActivity.java
public void setAmazonS3Client(CognitoCachingCredentialsProvider credentialsProvider) { // Create an S3 client amazonS3Client = new AmazonS3Client(credentialsProvider); // Set the region of your S3 bucket amazonS3Client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1)); }
From source file:com.datatorrent.lib.io.fs.S3BlockReader.java
License:Apache License
@Override public void setup(Context.OperatorContext context) { super.setup(context); s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretAccessKey)); ((S3BlockReaderContext) readerContext).setBucketName(bucketName); ((S3BlockReaderContext) readerContext).setS3Client(s3Client); }
From source file:com.davidsoergel.s3napback.StreamingTransferManager.java
License:Apache License
public StreamingTransferManager(AWSCredentials credentials) { this(new AmazonS3Client(credentials)); }
From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java
public static AmazonS3 connect() { loadProperties();// w ww . j a va 2 s . c o m BasicAWSCredentials awsCreds = new BasicAWSCredentials( prop.getProperty(MocksConstants.AWS_ACCESS_KEY_ID.getValue()), prop.getProperty(MocksConstants.AWS_SECRET_ACCESS_KEY.getValue())); s3Client = new AmazonS3Client(awsCreds); return s3Client; }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static AmazonS3 connect() { BasicAWSCredentials awsCreds = new BasicAWSCredentials(S3Properties.getInstance().getAwsAccessKeyId(), S3Properties.getInstance().getAwsSecretAccessKey()); s3Client = new AmazonS3Client(awsCreds); return s3Client; }
From source file:com.dongli.model.MyAWSStorage.java
License:Open Source License
private MyAWSStorage() { myCredentials = new BasicAWSCredentials(MyConfiguration.getInstance().accessKey, MyConfiguration.getInstance().secretKey); s3client = new AmazonS3Client(myCredentials); }
From source file:com.dustindoloff.s3websitedeploy.Main.java
License:Apache License
public static void main(final String[] args) { final Options options = buildOptions(); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {//from w ww . j a v a2 s .co m commandLine = parser.parse(options, args); } catch (final ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("s3WebsiteDeploy", options); System.exit(1); return; } final File websiteZip = new File(commandLine.getOptionValue(ARG_WEBSITE_ZIP)); final String s3Bucket = commandLine.getOptionValue(ARG_BUCKET); final String awsAccessKey = commandLine.getOptionValue(ARG_AWS_ACCESS_KEY); final String awsSecretKey = commandLine.getOptionValue(ARG_AWS_SECRET_KEY); final ZipFile zipFile = getAsValidZip(websiteZip); if (zipFile == null) { System.out.println("Invalid zip file passed in"); System.exit(2); return; } System.out.println("Running S3 Website Deploy"); final AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); final Region bucketRegion = getBucketRegion(s3Client, s3Bucket); if (bucketRegion == null) { System.out.println("Unable to get the region for the bucket."); System.exit(3); return; } s3Client.setRegion(bucketRegion); if (!emptyBucket(s3Client, s3Bucket)) { System.out.println("Unable to upload to empty bucket."); System.exit(4); return; } if (!upload(s3Client, s3Bucket, zipFile)) { System.out.println("Unable to upload to S3."); System.exit(5); return; } System.out.println("Deployment Complete"); }
From source file:com.eBilling.util.S3Example.java
void uploadfile(AWSCredentials credentials) { AmazonS3 s3client = new AmazonS3Client(credentials); try {/*ww w. ja v a 2 s . com*/ File file = new File(uploadFileName); PutObjectRequest p = new PutObjectRequest(bucketName, keyName, file); p.setCannedAcl(CannedAccessControlList.PublicRead); s3client.putObject(p); String _finalUrl = "https://" + bucketName + ".s3.amazonaws.com/" + keyName; System.out.println(_finalUrl); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }