@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); }
@Override protected void obtainResource() throws Exception { // See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); this.resource = AmazonKinesisAsyncClientBuilder.standard() .withClientConfiguration( new ClientConfiguration() .withMaxErrorRetry(0) .withConnectionTimeout(1000)) .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration("http://localhost:" + this.port, Regions.DEFAULT_REGION.getName())) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", ""))) .build(); // Check connection this.resource.listStreams(); }
private GetMediaWorker(Regions region, AWSCredentialsProvider credentialsProvider, String streamName, StartSelector startSelector, String endPoint, MkvElementVisitor elementVisitor) { super(region, credentialsProvider, streamName); AmazonKinesisVideoMediaClientBuilder builder = AmazonKinesisVideoMediaClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region.getName())) .withCredentials(getCredentialsProvider()); this.videoMedia = builder.build(); this.elementVisitor = elementVisitor; this.startSelector = startSelector; }
/** * 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(); }
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(); }
@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(); }
/** * Creates an {@link S3Connector} instance with embedded {@link AmazonS3 Amazon Web Services S3 SDK Client} from * {@link S3ServiceInfo}. * @param serviceInfo S3ServiceInfo provided by {@link org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator} * implementation included within the application. * @param serviceConnectorConfig * @return */ @Override public S3Connector create(S3ServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { AWSCredentials credentials = new BasicAWSCredentials(serviceInfo.getAccessKey(), serviceInfo.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); AwsClientBuilder.EndpointConfiguration endpointConfig = new AwsClientBuilder.EndpointConfiguration( serviceInfo.getEndpoint(), Region.getRegion(Regions.DEFAULT_REGION).getName()); AmazonS3 amazonS3 = AmazonS3ClientBuilder .standard() .withEndpointConfiguration(endpointConfig) .withCredentials(credentialsProvider) .enablePathStyleAccess() .build(); if (serviceInfo.getBucket() != null) { log.debug("Creating connector addressing ECS bucket: " + serviceInfo.getBucket()); return new S3Connector(amazonS3, serviceInfo.getEndpoint(), serviceInfo.getBucket()); } else { log.debug("Creating connector addressing ECS namespace."); return new S3Connector(amazonS3, serviceInfo.getEndpoint()); } }
/** * Creates an AmazonKinesis client. * @param configProps configuration properties containing the access key, secret key, and region * @return a new AmazonKinesis client */ public static AmazonKinesis createKinesisClient(Properties configProps) { // set a Flink-specific user agent ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig() .withUserAgentPrefix(String.format(USER_AGENT_FORMAT, EnvironmentInformation.getVersion(), EnvironmentInformation.getRevisionInformation().commitId)); // utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard() .withCredentials(AWSUtil.getCredentialsProvider(configProps)) .withClientConfiguration(awsClientConfig) .withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION))); if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) { // Set signingRegion as null, to facilitate mocking Kinesis for local tests builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration( configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT), null)); } return builder.build(); }
@BeforeClass public static void setUpClass() throws IOException, InterruptedException { File dir = new File(new File("target", UUID.randomUUID().toString()), "fakes3_root").getAbsoluteFile(); Assert.assertTrue(dir.mkdirs()); fakeS3Root = dir.getAbsolutePath(); port = TestUtil.getFreePort(); fakeS3 = new FakeS3(fakeS3Root, port); Assume.assumeTrue("Please install fakes3 in your system", fakeS3.fakes3Installed()); //Start the fakes3 server executorService = Executors.newSingleThreadExecutor(); executorService.submit(fakeS3); BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar"); s3client = AmazonS3ClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:" + port, null)) .withPathStyleAccessEnabled(true) .withChunkedEncodingDisabled(true) // FakeS3 does not correctly calculate checksums with chunked encoding enabled. .build(); TestUtil.createBucket(s3client, BUCKET_NAME); TestUtil.createBucket(s3client, SECOND_BUCKET_NAME); }
protected AmazonS3 createAmazonS3() { return AmazonS3ClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withEndpointConfiguration(new AwsClientBuilder .EndpointConfiguration(env("S3_HOST"), "eu-west")) .withPathStyleAccessEnabled(true) .build(); }
static AWSLogs createLogsClient(CloudwatchLogsConfig config) { AWSLogsClientBuilder builder = AWSLogsClientBuilder.standard(); if (config.getEndpoint() != null) { // Non-AWS mock endpoint builder.setCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())); builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion())); } else { builder.setRegion(config.getRegion()); } return builder.build(); }
@Test(expected = IllegalArgumentException.class) public void whenBogusEndpointIsSet_constructionFails() throws Exception { KmsMasterKeyProvider.builder() .withClientBuilder( AWSKMSClientBuilder.standard() .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration( "https://this.does.not.exist.example.com", "bad-region") ) ); }
public static AmazonEC2AsyncClient getAsyncClient( AuthCredentialsServiceState credentials, String region, ExecutorService executorService) { ClientConfiguration configuration = new ClientConfiguration(); configuration.setMaxConnections(100); 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))); AmazonEC2AsyncClientBuilder ec2AsyncClientBuilder = AmazonEC2AsyncClientBuilder .standard() .withClientConfiguration(configuration) .withCredentials(awsStaticCredentialsProvider) .withExecutorFactory(() -> executorService); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsClientMock()) { configuration.addHeader(AWS_REGION_HEADER, region); ec2AsyncClientBuilder.setClientConfiguration(configuration); AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAWSMockHost() + AWS_MOCK_EC2_ENDPOINT, region); ec2AsyncClientBuilder.setEndpointConfiguration(endpointConfiguration); } else { ec2AsyncClientBuilder.setRegion(region); } return (AmazonEC2AsyncClient) ec2AsyncClientBuilder.build(); }
public static AmazonCloudWatchAsyncClient getStatsAsyncClient( AuthCredentialsServiceState credentials, String region, ExecutorService executorService, boolean isMockRequest) { 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))); AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder .standard() .withClientConfiguration(configuration) .withCredentials(awsStaticCredentialsProvider) .withExecutorFactory(() -> executorService); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsClientMock()) { configuration.addHeader(AWS_REGION_HEADER, region); amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration); AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region); amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration); } else { amazonCloudWatchAsyncClientBuilder.setRegion(region); } return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build(); }
public static TransferManager getS3TransferManager(AuthCredentialsServiceState credentials, String region, ExecutorService executorService) { AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(credentials.privateKeyId, EncryptionUtils.decrypt(credentials.privateKey))); AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() .withCredentials(awsStaticCredentialsProvider) .withForceGlobalBucketAccessEnabled(true); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsS3Proxy()) { AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAwsS3ProxyHost(), region); amazonS3ClientBuilder.setEndpointConfiguration(endpointConfiguration); } else { amazonS3ClientBuilder.setRegion(region); } TransferManagerBuilder transferManagerBuilder = TransferManagerBuilder.standard() .withS3Client(amazonS3ClientBuilder.build()) .withExecutorFactory(() -> executorService) .withShutDownThreadPools(false); return transferManagerBuilder.build(); }
public static AmazonElasticLoadBalancingAsyncClient getLoadBalancingAsyncClient( AuthCredentialsServiceState credentials, String region, ExecutorService executorService) { 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))); AmazonElasticLoadBalancingAsyncClientBuilder amazonElasticLoadBalancingAsyncClientBuilder = AmazonElasticLoadBalancingAsyncClientBuilder .standard() .withClientConfiguration(configuration) .withCredentials(awsStaticCredentialsProvider) .withExecutorFactory(() -> executorService); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsClientMock()) { AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAWSMockHost() + AWS_MOCK_LOAD_BALANCING_ENDPOINT, region); amazonElasticLoadBalancingAsyncClientBuilder .setEndpointConfiguration(endpointConfiguration); } else { amazonElasticLoadBalancingAsyncClientBuilder.setRegion(region); } return (AmazonElasticLoadBalancingAsyncClient) amazonElasticLoadBalancingAsyncClientBuilder .build(); }
private AWSSecurityTokenService securityTokenService(AWSCredentialsProvider credentialsProvider) { AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard() .withCredentials(credentialsProvider); if (config.stsEndpoint().isPresent()) { builder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(config.getStsEndpoint(), config.getStsRegionName()) ); } else { builder.withRegion(config.getStsRegionName()); } return builder.build(); }
@Override public AmazonSQS get(SqsModule.EndpointConfig config) { AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard(); builder.withCredentials(credentialsProvider); if (config.endpoint().isPresent()) { builder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegionName()) ); } else { builder.withRegion(Regions.fromName(config.getRegionName())); } return builder.build(); }
@Override public AmazonSNS get(SnsModule.EndpointConfig config) { AmazonSNSClientBuilder builder = AmazonSNSClientBuilder.standard(); builder.withCredentials(credentialsProvider); if (config.endpoint().isPresent()) { builder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegionName()) ); } else { builder.withRegion(config.getRegionName()); } return builder.build(); }
public AmazonS3 newS3Client(S3SinkConnectorConfig config) { AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard() .withAccelerateModeEnabled(config.getBoolean(S3SinkConnectorConfig.WAN_MODE_CONFIG)) .withPathStyleAccessEnabled(true) .withCredentials(new DefaultAWSCredentialsProviderChain()); builder = url == null ? builder.withRegion(config.getString(S3SinkConnectorConfig.REGION_CONFIG)) : builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, "")); return builder.build(); }
@Override public AmazonKinesis getKinesisClient() { AmazonKinesisClientBuilder clientBuilder = AmazonKinesisClientBuilder.standard().withCredentials(getCredentialsProvider()); if (serviceEndpoint == null) { clientBuilder.withRegion(region); } else { clientBuilder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName())); } return clientBuilder.build(); }
@Override public AmazonCloudWatch getCloudWatchClient() { AmazonCloudWatchClientBuilder clientBuilder = AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvider()); if (serviceEndpoint == null) { clientBuilder.withRegion(region); } else { clientBuilder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName())); } return clientBuilder.build(); }
@VisibleForTesting static AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(final Optional<String> endpoint, final String signingRegion) { Preconditions.checkArgument(endpoint != null, "must provide an optional endpoint and not null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(signingRegion), "must provide a signing region"); final String expectedServiceEndpoint = "https://" + Region.getRegion(Regions.fromName(signingRegion)).getServiceEndpoint(AmazonDynamoDB.ENDPOINT_PREFIX); if (endpoint.isPresent() && !Strings.isNullOrEmpty(endpoint.get())) { final String regionParsedFromEndpoint = AwsHostNameUtils.parseRegion(endpoint.get(), AmazonDynamoDB.ENDPOINT_PREFIX); Preconditions.checkArgument(regionParsedFromEndpoint == null || signingRegion.equals(regionParsedFromEndpoint)); return new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signingRegion); } else { //Regions.fromName will throw IllegalArgumentException if signingRegion is not valid. return new AwsClientBuilder.EndpointConfiguration(expectedServiceEndpoint, signingRegion); } }
private static AmazonKinesis getKinesisClient(ClientConfiguration awsClientConfig, KinesisConfigBean conf) throws StageException { AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder .standard() .withClientConfiguration(checkNotNull(awsClientConfig)) .withCredentials(AWSUtil.getCredentialsProvider(conf.awsConfig)); if (AWSRegions.OTHER == conf.region) { builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(conf.endpoint, null)); } else { builder.withRegion(conf.region.getLabel()); } return builder.build(); }
private void createConnection( Stage.Context context, String configPrefix, ProxyConfig proxyConfig, List<Stage.ConfigIssue> issues, int maxErrorRetries ) throws StageException { AWSCredentialsProvider credentials = AWSUtil.getCredentialsProvider(awsConfig); ClientConfiguration clientConfig = AWSUtil.getClientConfiguration(proxyConfig); if (maxErrorRetries >= 0) { clientConfig.setMaxErrorRetry(maxErrorRetries); } AmazonS3ClientBuilder builder = AmazonS3ClientBuilder .standard() .withCredentials(credentials) .withClientConfiguration(clientConfig) .withChunkedEncodingDisabled(awsConfig.disableChunkedEncoding) .withPathStyleAccessEnabled(true); if (region == AWSRegions.OTHER) { if (endpoint == null || endpoint.isEmpty()) { issues.add(context.createConfigIssue(Groups.S3.name(), configPrefix + "endpoint", Errors.S3_SPOOLDIR_10)); return; } builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null)); } else { builder.withRegion(region.getLabel()); } s3Client = builder.build(); }
@Override protected List<ConfigIssue> init() { List<ConfigIssue> issues = super.init(); errorRecordHandler = new DefaultErrorRecordHandler(getContext()); if (!issues.isEmpty()) { return issues; } conf.init(getContext(), issues); if (!issues.isEmpty()) { return issues; } generatorFactory = conf.dataFormatConfig.getDataGeneratorFactory(); try { AmazonKinesisFirehoseClientBuilder builder = AmazonKinesisFirehoseClientBuilder .standard() .withCredentials(AWSUtil.getCredentialsProvider(conf.awsConfig)); if (conf.region == AWSRegions.OTHER) { builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(conf.endpoint, null)); } else { builder.withRegion(conf.region.getLabel()); } firehoseClient = builder.build(); } catch (StageException ex) { LOG.error(Utils.format(Errors.KINESIS_12.getMessage(), ex.toString()), ex); issues.add(getContext().createConfigIssue( Groups.KINESIS.name(), "kinesisConfig.awsConfig.awsAccessKeyId", Errors.KINESIS_12, ex.toString() )); } return issues; }
@BeforeClass public static void setUpClass() throws Exception { setupS3(); BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar"); s3client = AmazonS3ClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:" + port, null)) .withPathStyleAccessEnabled(true) .withChunkedEncodingDisabled(true) .build(); TestUtil.createBucket(s3client, SOURCE_BUCKET_NAME); TestUtil.createBucket(s3client, TARGET_BUCKET_NAME); testDir = new File("target", UUID.randomUUID().toString()).getAbsoluteFile(); Assert.assertTrue(testDir.mkdirs()); String filePath1 = testDir.getAbsolutePath() + "/" + FILE_NAME_1; String filePath2 = testDir.getAbsolutePath() + "/" + FILE_NAME_2; writeTextToFile(filePath1, SAMPLE_TEXT_TO_FILE_PATH_1); writeTextToFile(filePath2, SAMPLE_TEXT_TO_FILE_PATH_2); s3client.putObject(new PutObjectRequest(SOURCE_BUCKET_NAME, OBJECT_KEY_1, new File(filePath1))); s3client.putObject(new PutObjectRequest(SOURCE_BUCKET_NAME, OBJECT_KEY_2, new File(filePath2))); }
@SuppressWarnings("unchecked") @Override protected T createInstance() throws Exception { String builderName = this.clientClass.getName() + "Builder"; Class<?> className = ClassUtils.resolveClassName(builderName, ClassUtils.getDefaultClassLoader()); Method method = ClassUtils.getStaticMethod(className, "standard"); Assert.notNull(method, "Could not find standard() method in class:'" + className.getName() + "'"); AwsClientBuilder<?, T> builder = (AwsClientBuilder<?, T>) ReflectionUtils.invokeMethod(method, null); if (this.executor != null) { AwsAsyncClientBuilder<?, T> asyncBuilder = (AwsAsyncClientBuilder<?, T>) builder; asyncBuilder.withExecutorFactory((ExecutorFactory) () -> this.executor); } if (this.credentialsProvider != null) { builder.withCredentials(this.credentialsProvider); } if (this.customRegion != null) { builder.withRegion(this.customRegion.getName()); } else if (this.regionProvider != null) { builder.withRegion(this.regionProvider.getRegion().getName()); } else { builder.withRegion(Regions.DEFAULT_REGION); } return builder.build(); }
/** * returns keypairs as a json string */ @Action(value = "/manage/getKeyPairJSON" ) public String getKeyPairJSON() { AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId()); //set AWS credentials for service BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey()); AmazonEC2 service = AmazonEC2ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .withClientConfiguration(AWSClientConfig.getClientConfig()) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ec2Key.getEc2Region(), ec2RegionMap.get(ec2Key.getEc2Region()))).build(); DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest(); DescribeKeyPairsResult describeKeyPairsResult = service.describeKeyPairs(describeKeyPairsRequest); List<KeyPairInfo> keyPairInfoList = describeKeyPairsResult.getKeyPairs(); String json = new Gson().toJson(keyPairInfoList); try { servletResponse.getOutputStream().write(json.getBytes()); } catch (Exception ex) { log.error(ex.toString(), ex); } return null; }
/** * You can use mvn to run DynamoDBLocalFixture, e.g. * <p> * $ mvn clean package * <p> * $ mvn exec:java -Dexec.mainClass="com.amazonaws.services.dynamodbv2.DynamoDBLocalFixture" \ * -Dexec.classpathScope="test" \ * -Dsqlite4java.library.path=target/dependencies * <p> * It's recommended to run "aws configure" one time before you run DynamoDBLocalFixture * * @param args - no args * @throws Exception */ public static void main(String[] args) throws Exception { AmazonDynamoDB dynamodb = null; try { // Create an in-memory and in-process instance of DynamoDB Local that skips HTTP dynamodb = DynamoDBEmbedded.create().amazonDynamoDB(); // use the DynamoDB API with DynamoDBEmbedded listTables(dynamodb.listTables(), "DynamoDB Embedded"); } finally { // Shutdown the thread pools in DynamoDB Local / Embedded if(dynamodb != null) { dynamodb.shutdown(); } } // Create an in-memory and in-process instance of DynamoDB Local that runs over HTTP final String[] localArgs = { "-inMemory" }; DynamoDBProxyServer server = null; try { server = ServerRunner.createServerFromCommandLineArgs(localArgs); server.start(); dynamodb = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration( // we can use any region here new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")) .build(); // use the DynamoDB API over HTTP listTables(dynamodb.listTables(), "DynamoDB Local over HTTP"); } finally { // Stop the DynamoDB Local endpoint if(server != null) { server.stop(); } } }
protected void configureClient(AwsClientBuilder clientBuilder) { clientBuilder.withCredentials(credentialsProvider).withRegion(region); }
public <T, B extends AwsClientBuilder<B, T>> T create(final AwsClientBuilder<B, T> builder) { return builder // .withCredentials(credentialsProvider) // .withRegion(region) // .build(); }
public static AmazonS3 getS3Client() { BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY); /* //old v1.10 client ClientConfiguration cc = new ClientConfiguration(); //cc.setProxyHost("localhost"); //cc.setProxyPort(8888); // Force use of v2 Signer. //cc.setSignerOverride("S3SignerType"); AmazonS3Client client = new AmazonS3Client(creds, cc); client.setEndpoint(S3_ENDPOINT); */ // 1.11-100 good standard/basic with v4 auth doesn't work with 1.11-21 though AwsClientBuilder.EndpointConfiguration ec = new AwsClientBuilder.EndpointConfiguration(S3_ENDPOINT,"us-east-1"); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)) .withEndpointConfiguration(ec).build(); /* // new client,but using v2 auth ClientConfiguration cc = new ClientConfiguration(); cc.setSignerOverride("S3SignerType"); AmazonS3ClientBuilder.EndpointConfiguration ec = new AmazonS3ClientBuilder.EndpointConfiguration(S3_ENDPOINT,"us-east-1"); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)) .withClientConfiguration(cc) .withEndpointConfiguration(ec).withPathStyleAccessEnabled(true) .build(); */ /* //new client but deprecated way of using path style bucket naming S3ClientOptions opts = new S3ClientOptions(); opts.setPathStyleAccess(true); client.setS3ClientOptions(opts); */ return client; }
/** * Create a simple instance of {@code S3Module}. * * @param lifecycle The application life cycle * @param configuration The application configuration * @since 16.03.13 */ @Inject public AmazonS3ModuleInitializer(final ApplicationLifecycle lifecycle, final Config configuration) { final String accessKey; final String secretKey; if (configuration.hasPath("aws.s3.authKey")) { accessKey = configuration.getString("aws.s3.authKey"); } else { accessKey = configuration.getString("aws.authKey"); } if (configuration.hasPath("aws.s3.authSecret")) { secretKey = configuration.getString("aws.s3.authSecret"); } else { secretKey = configuration.getString("aws.authSecret"); } final String endPoint = configuration.getString("aws.s3.endPoint"); final String signingRegion = configuration.getString("aws.s3.signingRegion"); final boolean withPathStyle = configuration.hasPath("aws.s3.withPathStyle") && configuration.getBoolean("aws.s3.withPathStyle"); final boolean withChunkedEncodingDisabled = configuration.hasPath("aws.s3.disableChunkedEncoding") && configuration.getBoolean("aws.s3.disableChunkedEncoding"); PlayS3.bucketName = configuration.getString("aws.s3.bucketName"); PlayS3.publicUrl = configuration.hasPath("aws.s3.publicUrl") ? configuration.getString("aws.s3.publicUrl") : "/"; if (!PlayS3.publicUrl.endsWith("/")) { PlayS3.publicUrl += "/"; } if (accessKey == null || secretKey == null || PlayS3.bucketName == null) { throw new RuntimeException("S3Module is not properly configured"); } PlayS3.amazonS3 = AmazonS3ClientBuilder .standard() .withCredentials(new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return new BasicAWSCredentials(accessKey, secretKey); } @Override public void refresh() { // Not used with basic AWS credentials } }) .withPathStyleAccessEnabled(withPathStyle) .withChunkedEncodingDisabled(withChunkedEncodingDisabled) .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(endPoint, signingRegion) ) .build(); try { PlayS3.amazonS3.createBucket(PlayS3.bucketName); } catch (final AmazonS3Exception ex) { if (ex.getErrorCode().compareTo("BucketAlreadyOwnedByYou") != 0 && ex.getErrorCode().compareTo("AccessDenied") != 0) { throw ex; } } finally { Logger.info("Using PlayS3 Bucket: " + PlayS3.bucketName); } lifecycle.addStopHook(() -> CompletableFuture.completedFuture(null)); }
@Test public void getEndpointConfiguration_whenEndpointEmptyAndRegionValid_returnConfig() { final AwsClientBuilder.EndpointConfiguration config = DynamoDbDelegate.getEndpointConfiguration(EMPTY_ENDPOINT, VALID_REGION); assertEquals(VALID_REGION, config.getSigningRegion()); assertTrue(config.getServiceEndpoint().contains(VALID_REGION)); }
@Test public void getEndpointConfiguration_whenEndpointValidEmptyStringAndRegionValid_throwIllegalArgumentException() { final AwsClientBuilder.EndpointConfiguration config = DynamoDbDelegate.getEndpointConfiguration(VALID_EMPTY_STRING_ENDPOINT, VALID_REGION); assertEquals(VALID_REGION, config.getSigningRegion()); assertEquals("https://dynamodb." + VALID_REGION + ".amazonaws.com", config.getServiceEndpoint()); }
@Test public void getEndpointConfiguration_whenEndpointValidNotAUrlAndRegionValid_returnConfig() { final AwsClientBuilder.EndpointConfiguration config = DynamoDbDelegate.getEndpointConfiguration(VALID_NOT_A_URL_ENDPOINT, VALID_REGION); assertEquals(VALID_REGION, config.getSigningRegion()); assertEquals(VALID_NOT_A_URL_ENDPOINT.get(), config.getServiceEndpoint()); }
@Test public void getEndpointConfiguration_whenEndpointValidLocalAndRegionValid_returnsConfig() { final AwsClientBuilder.EndpointConfiguration config = DynamoDbDelegate.getEndpointConfiguration(VALID_DYNAMODB_LOCAL_ENDPOINT, VALID_REGION); assertEquals(VALID_REGION, config.getSigningRegion()); assertEquals(VALID_DYNAMODB_LOCAL_ENDPOINT.get(), config.getServiceEndpoint()); }
@Test public void getEndpointConfiguration_whenEndpointValidServiceAndRegionValid_returnsConfig() { final AwsClientBuilder.EndpointConfiguration config = DynamoDbDelegate.getEndpointConfiguration(VALID_DYNAMODB_ENDPOINT, VALID_REGION); assertEquals(VALID_REGION, config.getSigningRegion()); assertEquals(VALID_DYNAMODB_ENDPOINT.get(), config.getServiceEndpoint()); }