@Bean public Region awsRegion() { Region region; if(regionString != null && !regionString.isEmpty()) { region = RegionUtils.getRegion(regionString); } else { AwsRegionProvider regionProvider = new DefaultAwsRegionProviderChain(); region = RegionUtils.getRegion(regionProvider.getRegion()); } if(region == null) { throw new BeanInitializationException("Unable to determine AWS region"); } return region; }
@Bean String region(ZipkinElasticsearchStorageProperties es, ZipkinElasticsearchAwsStorageProperties aws) { List<String> hosts = es.getHosts(); String domain = aws.getDomain(); if (hosts != null && domain != null) { log.warning( format("Expected exactly one of hosts or domain: instead saw hosts '%s' and domain '%s'." + " Ignoring hosts and proceeding to look for domain. Either unset ES_HOSTS or " + "ES_AWS_DOMAIN to suppress this message.", hosts, domain)); } if (aws.getRegion() != null) { return aws.getRegion(); } else if (domain != null) { return new DefaultAwsRegionProviderChain().getRegion(); } else { return regionFromAwsUrls(hosts).get(); } }
public AwsFacade createFacade() throws MissingArgumentException, CfnAssistException, InterruptedException { if (awsFacade==null) { init(); SNSEventSource eventSource = new SNSEventSource(snsClient, sqsClient); MonitorStackEvents monitor; if (snsMonitoring) { monitor = new SNSMonitor(eventSource, cfnRepository); } else { monitor = new PollingStackMonitor(cfnRepository); } monitor.init(); AwsRegionProvider regionProvider = new DefaultAwsRegionProviderChain(); awsFacade = new AwsFacade(monitor, cfnRepository, vpcRepository, elbRepository, cloudRepository, notificationSender, identityProvider); } return awsFacade; }
@Before public void beforeEachTestRuns() { AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); AmazonEC2 ec2Client = EnvironmentSetupForTests.createEC2Client(); AmazonElasticLoadBalancing awsElbClient = EnvironmentSetupForTests.createELBClient(); AmazonCloudFormation cfnClient = EnvironmentSetupForTests.createCFNClient(); AmazonRDS awsRdsClient = EnvironmentSetupForTests.createRDSClient(); CloudClient cloudClient = new CloudClient(ec2Client, new DefaultAwsRegionProviderChain()); LoadBalancerClient elbClient = new LoadBalancerClient(awsElbClient); VpcRepository vpcRepository = new VpcRepository(cloudClient); CloudFormationClient cloudFormationClient = new CloudFormationClient(cfnClient); cloudRepository = new CloudRepository(cloudClient); ResourceRepository cfnRepository = new CfnRepository(cloudFormationClient, cloudRepository, "CfnAssist"); elbRepository = new ELBRepository(elbClient, vpcRepository, cfnRepository); rdsClient = new RDSClient(awsRdsClient); }
@Before public void beforeEveryTestRun() { vpcRepository = new VpcRepository(new CloudClient(ec2Client, new DefaultAwsRegionProviderChain())); altProjectAndEnv = EnvironmentSetupForTests.getAltProjectAndEnv(); EnvironmentSetupForTests.getMainProjectAndEnv(); altEnvVPC = EnvironmentSetupForTests.findAltVpc(vpcRepository); deletesStacks = new DeletesStacks(cfnClient); deletesStacks.ifPresent(EnvironmentSetupForTests.TEMPORARY_STACK) .ifPresent("CfnAssistTest01createSubnet") .ifPresent("CfnAssistTest02createAcls") .ifPresent("CfnAssistTestsimpleStack") .ifPresent("CfnAssistTestsubnet") .ifPresent("CfnAssist876TestelbAndInstance") .ifPresent("CfnAssistTestsimpleStackWithAZ"); deletesStacks.act(); testName = test.getMethodName(); }
@Before public void beforeEveryTestRun() { deleteTestKeysFromBucket(); vpcRepository = new VpcRepository(new CloudClient(ec2Client, new DefaultAwsRegionProviderChain())); projectAndEnv = EnvironmentSetupForTests.getMainProjectAndEnv(); deletesStacks = new DeletesStacks(cfnClient); deletesStacks.ifPresent(EnvironmentSetupForTests.TEMPORARY_STACK) .ifPresent("CfnAssistTest01createSubnet") .ifPresent("CfnAssistTest02createAcls") .ifPresent("CfnAssistTestsimpleStack"); deletesStacks.act(); testName = test.getMethodName(); }
private Optional<Region> getRegionFromMetadata() { try { Region resolvedRegion = null; if (EC2MetadataUtils.getInstanceInfo() != null) { if (EC2MetadataUtils.getInstanceInfo().getRegion() != null) { resolvedRegion = Region.fromName(EC2MetadataUtils.getInstanceInfo().getRegion()); } else { // fallback to provider chain if region is not exposed resolvedRegion = Region.fromName(new DefaultAwsRegionProviderChain().getRegion()); } } return Optional.ofNullable(resolvedRegion); } catch (SdkClientException e) { return Optional.empty(); } }
private String defaultRegion() { try { return new DefaultAwsRegionProviderChain().getRegion(); } catch (SdkClientException e) { String region = Regions.DEFAULT_REGION.getName(); log.warn("Default AWS region not configured, using {}", region, e); return region; } }
private void createProviders() { loadBalancerClient = new LoadBalancerClient(elbClient); AwsRegionProvider regionProvider = new DefaultAwsRegionProviderChain(); cloudClient = new CloudClient(ec2Client, regionProvider); formationClient = new CloudFormationClient(cfnClient); datastoreClient = new RDSClient(rdsClient); notificationSender = new SNSNotificationSender(snsClient); identityProvider = new IdentityProvider(iamClient); }
@BeforeClass public static void onceBeforeClassRuns() { DefaultAWSCredentialsProviderChain credentialsProvider = new DefaultAWSCredentialsProviderChain(); ec2Client = EnvironmentSetupForTests.createEC2Client(); regionProvider = new DefaultAwsRegionProviderChain(); vpcRepository = new VpcRepository(new CloudClient(ec2Client, regionProvider)); cfnClient = EnvironmentSetupForTests.createCFNClient(); AmazonSNS snsClient = EnvironmentSetupForTests.createSNSClient(); AmazonSQS sqsClient = EnvironmentSetupForTests.createSQSClient(); snsNotifProvider = new SNSEventSource(snsClient, sqsClient); new DeletesStacks(cfnClient).ifPresent("queryStackTest"). ifPresent("createStackTest"). ifPresent("createIAMStackTest").act(); }
@Before public void beforeEachTestRuns() { client = new CloudClient(ec2Client, new DefaultAwsRegionProviderChain()); deleteGroupIfPresent(); CreateSecurityGroupRequest createRequest = new CreateSecurityGroupRequest(). withDescription("test group"). withGroupName(GROUP_NAME); CreateSecurityGroupResult result = ec2Client.createSecurityGroup(createRequest); groupId = result.getGroupId(); }
@Test public void shouldGetAvailabilityZones() { String regionName = new DefaultAwsRegionProviderChain().getRegion(); Map<String, AvailabilityZone> zones = cloudClient.getAvailabilityZones(); assertEquals(3, zones.size()); zones.forEach((name, zone) -> assertEquals(regionName, zone.getRegionName())); assertTrue(zones.containsKey("a")); assertTrue(zones.containsKey("b")); }
protected final String getRegion() { return new DefaultAwsRegionProviderChain().getRegion(); }
@Before public void beforeEachTestIsRun() { ec2Client = EnvironmentSetupForTests.createEC2Client(); cloudClient = new CloudClient(ec2Client, new DefaultAwsRegionProviderChain()); }
@Before public void beforeEveryTestRun() { VpcRepository vpcRepository = new VpcRepository(new CloudClient(ec2Client, new DefaultAwsRegionProviderChain())); altEnvVPC = EnvironmentSetupForTests.findAltVpc(vpcRepository); }