本文整理匯總了Java中com.amazonaws.services.s3.AmazonS3ClientBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java AmazonS3ClientBuilder類的具體用法?Java AmazonS3ClientBuilder怎麽用?Java AmazonS3ClientBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AmazonS3ClientBuilder類屬於com.amazonaws.services.s3包,在下文中一共展示了AmazonS3ClientBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: amazonS3Client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
/**
* S3 儲存客戶端
*
* @return 客戶端
*/
@Bean
@ConditionalOnProperty(value = "bigbug.storage.s3.enable", havingValue = "true")
AmazonS3Client amazonS3Client() {
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setProtocol(Protocol.HTTP);
BasicAWSCredentials basicAWSCredentials =
new BasicAWSCredentials(
storageProperties.getStorage().getS3().getAccessKey(),
storageProperties.getStorage().getS3().getSecretKey());
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withClientConfiguration(clientConfig)
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
storageProperties.getStorage().getS3().getEndpoint(), Regions.DEFAULT_REGION.getName()))
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.build();
}
示例2: getS3Client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
public static AmazonS3 getS3Client(final String region, final String roleArn) {
final Regions awsRegion = StringUtils.isNullOrEmpty(region) ? Regions.US_EAST_1 : Regions.fromName(region);
if (StringUtils.isNullOrEmpty(roleArn)) {
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).build();
} else {
final AssumeRoleRequest assumeRole = new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("io-klerch-mp3-converter");
final AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard().withRegion(awsRegion).build();
final Credentials credentials = sts.assumeRole(assumeRole).getCredentials();
final BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretAccessKey(),
credentials.getSessionToken());
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).withCredentials(new AWSStaticCredentialsProvider(sessionCredentials)).build();
}
}
示例3: setup
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
@Before
public void setup() throws IllegalAccessException, NoSuchFieldException {
Assume.assumeTrue(System.getProperty("skip.long") == null);
TestUtils.disableSslCertChecking();
amazonS3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
LocalstackTestRunner.getEndpointS3(),
LocalstackTestRunner.getDefaultRegion()))
.withChunkedEncodingDisabled(true)
.withPathStyleAccessEnabled(true).build();
amazonS3Client.createBucket(bucketName);
S3Config config = new S3Config();
Field field = StorageServiceImpl.class.getDeclaredField("s3TransferManager");
field.setAccessible(true);
field.set(underTest, config.s3TransferManager(amazonS3Client));
field = StorageServiceImpl.class.getDeclaredField("environment");
field.setAccessible(true);
field.set(underTest, environment);
}
示例4: S3Writer
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
public S3Writer(Replicator replicator) {
this.replicator = replicator;
this.client =
AmazonS3ClientBuilder.standard().withRegion(replicator.getConfig().s3.region).build();
this.copier = Executors.newFixedThreadPool(replicator.getConfig().redshift.maxConnections);
int queueSize = TABLE_QUEUE_SIZE / replicator.getConfig().tables.size();
queueSum = queueSize * replicator.getConfig().tables.size();
for (Config.Table table : replicator.getConfig().tables) {
copyQueues.put(table.name, new LinkedBlockingQueue<>(queueSize));
// We only allow 1 copy worker at a time to be copying to a given table, so we maintain this mapping.
tableCopyLocks.put(table.name, new ReentrantLock());
uploadFormat(table);
}
for (int i = 0; i != replicator.getConfig().redshift.maxConnections; i++) {
this.copier.submit(new CopyWorker(this, copyQueues, tableCopyLocks));
}
this.uploader =
new ThreadPoolExecutor(1, 100, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(20));
}
示例5: getS3Value
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
/**
* Attempt to fetch a secret from S3.
*
* @param s3path where to fetch it from
* @return the content of the file found on S3
* @throws IOException on problems streaming the content of the file
* @throws AmazonS3Exception on problems communicating with amazon
*/
private String getS3Value(final SecretPath s3path) throws IOException, AmazonS3Exception {
LOG.info("Fetching secret from s3://" + s3path.bucket + "/" + s3path.key);
if (s3Client == null) {
if (awsCredentialsProvider != null) {
s3Client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider)
.build();
} else {
s3Client = AmazonS3ClientBuilder.standard().build();
}
}
final S3Object s3object
= s3Client.getObject(new GetObjectRequest(s3path.bucket, s3path.key));
final BufferedReader reader
= new BufferedReader(new InputStreamReader(s3object.getObjectContent()));
final StringBuilder b = new StringBuilder();
String line;
while((line = reader.readLine()) != null) {
b.append(line);
}
LOG.info("Found secret");
reader.close();
return b.toString();
}
示例6: setupS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
@BeforeClass
public static void setupS3() {
final ProfileCredentialsProvider credentialsProvider
= new ProfileCredentialsProvider(System.getenv("AWS_PROFILE"));
s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build();
bucket = System.getenv("AWS_S3_BUCKET");
if (! s3Client.doesBucketExist(bucket)) {
if (System.getenv("AWS_S3_CREATE_BUCKET") == null
|| !Boolean.parseBoolean(System.getenv("AWS_S3_CREATE_BUCKET"))) {
throw new IllegalStateException("Bucket does not exist and not allowed to create.");
}
s3Client.createBucket(bucket);
}
S3SecretHandler.setS3CredentialsProvider(credentialsProvider);
secretHandler = new S3SecretHandler();
}
示例7: LinkGeneratorLambdaHandler
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
LinkGeneratorLambdaHandler(String region, String jwtEncryptKeyArn, String pageStorageBucket, String authVerifyEndpointURL,
AWSCredentialsProvider awsCredential, String introPageTemplateName) throws IOException, TemplateException {
AWSKMS kmsClient = AWSKMSClientBuilder.standard()
.withCredentials(awsCredential)
.withRegion(region)
.build();
AmazonS3 s3client = AmazonS3ClientBuilder
.standard()
.withCredentials(awsCredential)
.withRegion(region)
.build();
kmsEncrypt = new KMSEncrypt(kmsClient, jwtEncryptKeyArn);
this.pageStorageBucket = pageStorageBucket;
this.authVerifyEndpointURL = authVerifyEndpointURL;
this.pageUploader = new PageUploader(s3client, pageStorageBucket);
this.introPageTemplate = new IntroPageTemplate(introPageTemplateName);
}
示例8: TextToSpeechConverter
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
public TextToSpeechConverter(final AlexaInput input) {
// the locale is coming with the speechlet request and indicates to source language to translate from
this.locale = input.getLocale();
// get translator
this.translator = TranslatorFactory.getTranslator(this.locale);
// the language is taken from the user input (slot value) and indicates to language to translate to
this.language = input.getSlotValue("language");
final ResourceUtteranceReader reader = new ResourceUtteranceReader("/out", "/voices.yml");
// the yaml reader reads values from YAML file to get a Polly voiceId for a language
this.yamlReader = new YamlReader(reader, locale);
// Polly client to request speech of a translated text
this.awsPolly = AmazonPollyClientBuilder.standard().build();
// S3 client to store MP3 with speech of a translated text
this.awsS3 = AmazonS3ClientBuilder.standard().build();
// session state handler to read/write skill state information to Alexa session
this.sessionStateHandler = input.getSessionStateHandler();
// dynamo state handler to read/write skill state information to DynamoDB
this.dynamoStateHandler = new AWSDynamoStateHandler(input.getSessionStateHandler().getSession(), SkillConfig.getDynamoTableName());
// retrieve voiceId from YAML file that maps to the language given by the user
voiceId = language != null ? yamlReader.getRandomUtterance(language.toLowerCase().replace(" ", "_")).orElse("") : "";
// language-specific prefix phrases that accidently made it into the text slot and should be removed
prefixesToRemove = yamlReader.getUtterances("PREFIXES_TO_REMOVE");
}
示例9: getS3Client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
public static AmazonS3Client getS3Client(AuthCredentialsServiceState credentials,
String regionId) {
ClientConfiguration configuration = new ClientConfiguration();
configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
DEFAULT_BACKOFF_STRATEGY,
DEFAULT_MAX_ERROR_RETRY,
false));
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
new BasicAWSCredentials(credentials.privateKeyId,
EncryptionUtils.decrypt(credentials.privateKey)));
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder
.standard()
.withClientConfiguration(configuration)
.withCredentials(awsStaticCredentialsProvider)
.withRegion(regionId);
if (isAwsClientMock()) {
throw new IllegalArgumentException("AWS Mock does not support S3 client");
}
return (AmazonS3Client) amazonS3ClientBuilder.build();
}
示例10: newS3Client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
public AmazonS3 newS3Client(S3SinkConnectorConfig config) {
ClientConfiguration clientConfiguration = newClientConfiguration(config);
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard()
.withAccelerateModeEnabled(
config.getBoolean(WAN_MODE_CONFIG)
)
.withPathStyleAccessEnabled(true)
.withCredentials(config.getCredentialsProvider())
.withClientConfiguration(clientConfiguration);
String region = config.getString(REGION_CONFIG);
if (StringUtils.isBlank(url)) {
builder = "us-east-1".equals(region)
? builder.withRegion(Regions.US_EAST_1)
: builder.withRegion(region);
} else {
builder = builder.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(url, region)
);
}
return builder.build();
}
示例11: newS3Client
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
@Override
public AmazonS3 newS3Client(S3SinkConnectorConfig config) {
final AWSCredentialsProvider provider = new AWSCredentialsProvider() {
private final AnonymousAWSCredentials credentials = new AnonymousAWSCredentials();
@Override
public AWSCredentials getCredentials() {
return credentials;
}
@Override
public void refresh() {
}
};
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard()
.withAccelerateModeEnabled(config.getBoolean(S3SinkConnectorConfig.WAN_MODE_CONFIG))
.withPathStyleAccessEnabled(true)
.withCredentials(provider);
builder = url == null ?
builder.withRegion(config.getString(S3SinkConnectorConfig.REGION_CONFIG)) :
builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, ""));
return builder.build();
}
示例12: 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);
}
}
示例13: 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));
}
示例14: 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));
}
示例15: authenticatedEncryption_CustomerManagedAsymmetricKey
import com.amazonaws.services.s3.AmazonS3ClientBuilder; //導入依賴的package包/類
/**
* Same as {@link #authenticatedEncryption_CustomerManagedKey()} except uses an asymmetric key pair and
* RSA/ECB/OAEPWithSHA-256AndMGF1Padding as the key wrapping algorithm.
*/
public void authenticatedEncryption_CustomerManagedAsymmetricKey() throws NoSuchAlgorithmException {
KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.AuthenticatedEncryption))
.withEncryptionMaterials(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(keyPair)))
.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));
}