本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3ClientBuilder.defaultClient方法的具体用法?Java AmazonS3ClientBuilder.defaultClient怎么用?Java AmazonS3ClientBuilder.defaultClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.AmazonS3ClientBuilder
的用法示例。
在下文中一共展示了AmazonS3ClientBuilder.defaultClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWebsiteConfig
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void getWebsiteConfig(String bucket_name)
{
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
BucketWebsiteConfiguration config =
s3.getBucketWebsiteConfiguration(bucket_name);
if (config == null) {
System.out.println("No website configuration found!");
} else {
System.out.format("Index document: %s\n",
config.getIndexDocumentSuffix());
System.out.format("Error document: %s\n",
config.getErrorDocument());
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.out.println("Failed to get website configuration!");
System.exit(1);
}
}
示例2: setBucketAcl
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void setBucketAcl(String bucket_name, String email, String access)
{
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("on bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getBucketAcl(bucket_name);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setBucketAcl(bucket_name, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例3: authenticatedEncryption_CustomerManagedKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* Uses AES/GCM with AESWrap key wrapping to encrypt the key. Uses v2 metadata schema. Note that authenticated
* encryption requires the bouncy castle provider to be on the classpath. Also, for authenticated encryption the size
* of the data can be no longer than 64 GB.
*/
public void authenticatedEncryption_CustomerManagedKey() throws NoSuchAlgorithmException {
SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.AuthenticatedEncryption))
.withEncryptionMaterials(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey)))
.build();
AmazonS3 s3NonEncrypt = AmazonS3ClientBuilder.defaultClient();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
s3NonEncrypt.putObject(BUCKET_NAME, NON_ENCRYPTED_KEY, "some other contents");
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, ENCRYPTED_KEY));
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, NON_ENCRYPTED_KEY));
}
示例4: authenticatedEncryption_RangeGet_CustomerManagedKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* For ranged GET we do not use authenticated encryption since we aren't reading the entire message and can't produce the
* MAC. Instead we use AES/CTR, an unauthenticated encryption algorithm. If {@link CryptoMode#StrictAuthenticatedEncryption}
* is enabled, ranged GETs will not be allowed since they do not use authenticated encryption..
*/
public void authenticatedEncryption_RangeGet_CustomerManagedKey() throws NoSuchAlgorithmException {
SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.AuthenticatedEncryption))
.withEncryptionMaterials(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey)))
.build();
AmazonS3 s3NonEncrypt = AmazonS3ClientBuilder.defaultClient();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
s3NonEncrypt.putObject(BUCKET_NAME, NON_ENCRYPTED_KEY, "some other contents");
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, ENCRYPTED_KEY));
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, NON_ENCRYPTED_KEY));
}
示例5: getBucketAcl
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void getBucketAcl(String bucket_name)
{
System.out.println("Retrieving ACL for bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
AccessControlList acl = s3.getBucketAcl(bucket_name);
List<Grant> grants = acl.getGrantsAsList();
for (Grant grant : grants) {
System.out.format(" %s: %s\n", grant.getGrantee().getIdentifier(),
grant.getPermission().toString());
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例6: encryptionOnly_CustomerManagedKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* Uses AES/CBC algorithm, no key wrapping.
*/
public void encryptionOnly_CustomerManagedKey() throws NoSuchAlgorithmException {
SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.EncryptionOnly))
.withEncryptionMaterials(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey)))
.build();
AmazonS3 s3NonEncrypt = AmazonS3ClientBuilder.defaultClient();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
s3NonEncrypt.putObject(BUCKET_NAME, NON_ENCRYPTED_KEY, "some other contents");
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, ENCRYPTED_KEY));
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, NON_ENCRYPTED_KEY));
}
示例7: encryptionOnly_KmsManagedKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* This uses the V2 metadata schema with a key wrap algorithm of 'kms' and a CEK algorithm of AES/CBC/PKCS5Padding.
*/
public void encryptionOnly_KmsManagedKey() throws NoSuchAlgorithmException {
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.EncryptionOnly))
// Can either be Key ID or alias (prefixed with 'alias/')
.withEncryptionMaterials(new KMSEncryptionMaterialsProvider("alias/s3-kms-key"))
.build();
AmazonS3 s3NonEncrypt = AmazonS3ClientBuilder.defaultClient();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
s3NonEncrypt.putObject(BUCKET_NAME, NON_ENCRYPTED_KEY, "some other contents");
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, ENCRYPTED_KEY));
System.out.println(s3Encryption.getObjectAsString(BUCKET_NAME, NON_ENCRYPTED_KEY));
}
示例8: getObjectAcl
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void getObjectAcl(String bucket_name, String object_key)
{
System.out.println("Retrieving ACL for object: " + object_key);
System.out.println(" in bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
List<Grant> grants = acl.getGrantsAsList();
for (Grant grant : grants) {
System.out.format(" %s: %s\n", grant.getGrantee().getIdentifier(),
grant.getPermission().toString());
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例9: strictAuthenticatedEncryption_KmsManagedKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* Same as authenticatedEncryption_KmsManagedKey except throws an exception when trying to get objects not encrypted with
* AES/GCM.
*/
public void strictAuthenticatedEncryption_KmsManagedKey() throws NoSuchAlgorithmException {
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.AuthenticatedEncryption))
// Can either be Key ID or alias (prefixed with 'alias/')
.withEncryptionMaterials(new KMSEncryptionMaterialsProvider("alias/s3-kms-key"))
.build();
AmazonS3 s3NonEncrypt = AmazonS3ClientBuilder.defaultClient();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
s3NonEncrypt.putObject(BUCKET_NAME, NON_ENCRYPTED_KEY, "some other contents");
try {
s3Encryption.getObjectAsString(BUCKET_NAME, NON_ENCRYPTED_KEY);
} catch (SecurityException e) {
// Strict authenticated encryption will throw an exception if an object is not encrypted with AES/GCM
System.err.println(NON_ENCRYPTED_KEY + " was not encrypted with AES/GCM");
}
}
示例10: setObjectAcl
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void setObjectAcl(String bucket_name, String object_key, String email, String access)
{
System.out.format("Setting %s access for %s\n", access, email);
System.out.println("for object: " + object_key);
System.out.println(" in bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
// get the current ACL
AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
// set access for the grantee
EmailAddressGrantee grantee = new EmailAddressGrantee(email);
Permission permission = Permission.valueOf(access);
acl.grantPermission(grantee, permission);
s3.setObjectAcl(bucket_name, object_key, acl);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
示例11: main
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static void main(String[] args)
{
final String USAGE = "\n" +
"To run this example, supply the name of a bucket to list!\n" +
"\n" +
"Ex: ListObjects <bucket-name>\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
System.out.format("Objects in S3 bucket %s:\n", bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
ObjectListing ol = s3.listObjects(bucket_name);
List<S3ObjectSummary> objects = ol.getObjectSummaries();
for (S3ObjectSummary os: objects) {
System.out.println("* " + os.getKey());
}
}
示例12: s3client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
/**
* Creates the S3 client {@link Bean}.
*
* Uses the default client, but if a region is unspecified, uses {@code us-east-1}.
*
* @return The S3 client.
*/
@Bean
public AmazonS3 s3client() {
try {
return AmazonS3ClientBuilder.defaultClient();
} catch (SdkClientException exception) {
API_LOG.info("Default S3 client failed to build, trying again with region us-east-1", exception);
return planB();
}
}
示例13: handleRequest
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
@Override
public Parameters handleRequest(Parameters parameters, Context context) {
context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
// The archive location of the snapshot will be decided by the alert
// flag
String newFilename;
if (parameters.getSendAlert()) {
newFilename = parameters.getS3Key().replace("upload/", "archive/alerts/");
} else {
newFilename = parameters.getS3Key().replace("upload/", "archive/falsepositives/");
}
// Ensure that the first two hyphens are used to create sub-directories
// in the file path
newFilename = newFilename.replaceFirst("-", "/");
newFilename = newFilename.replaceFirst("-", "/");
// Using the S3 client, first copy the file to the archive, and then
// delete the original
AmazonS3 client = AmazonS3ClientBuilder.defaultClient();
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(parameters.getS3Bucket(), parameters.getS3Key(), parameters.getS3Bucket(), newFilename);
client.copyObject(copyObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(parameters.getS3Bucket(), parameters.getS3Key());
client.deleteObject(deleteObjectRequest);
// Place the new location in the parameters
parameters.setS3ArchivedKey(newFilename);
context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
return parameters;
}
示例14: getBucket
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static Bucket getBucket(String bucket_name) {
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
Bucket named_bucket = null;
List<Bucket> buckets = s3.listBuckets();
for (Bucket b : buckets) {
if (b.getName().equals(bucket_name)) {
named_bucket = b;
}
}
return named_bucket;
}
示例15: createBucket
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //导入方法依赖的package包/类
public static Bucket createBucket(String bucket_name) {
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
Bucket b = null;
if (s3.doesBucketExist(bucket_name)) {
System.out.format("Bucket %s already exists.\n", bucket_name);
b = getBucket(bucket_name);
} else {
try {
b = s3.createBucket(bucket_name);
} catch (AmazonS3Exception e) {
System.err.println(e.getErrorMessage());
}
}
return b;
}