com.amazonaws.regions.RegionUtils Java Examples
The following examples show how to use
com.amazonaws.regions.RegionUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch NAT gateway info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<NatGateway>> fetchNATGatewayInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<NatGateway>> natGatwayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Nat Gateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeNatGatewaysResult rslt = ec2Client.describeNatGateways(new DescribeNatGatewaysRequest()); List<NatGateway> natGatwayList =rslt.getNatGateways(); if(! natGatwayList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId + " Type : Nat Gateway "+region.getName() + " >> "+natGatwayList.size()); natGatwayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), natGatwayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"nat",e.getMessage()); } } return natGatwayMap; }
Example #2
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch egress gateway. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<EgressOnlyInternetGateway>> fetchEgressGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<EgressOnlyInternetGateway>> egressGatewayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"egressgateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<EgressOnlyInternetGateway> egressGatewayList = ec2Client.describeEgressOnlyInternetGateways(new DescribeEgressOnlyInternetGatewaysRequest()).getEgressOnlyInternetGateways(); if(!egressGatewayList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Egress Gateway "+ region.getName()+" >> " + egressGatewayList.size()); egressGatewayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), egressGatewayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"egressgateway",e.getMessage()); } } return egressGatewayMap; }
Example #3
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch peering connections. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<VpcPeeringConnection>> fetchPeeringConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<VpcPeeringConnection>> peeringConnectionMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"peeringconnection\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VpcPeeringConnection> peeringConnectionList = ec2Client.describeVpcPeeringConnections().getVpcPeeringConnections(); if(!peeringConnectionList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Peering Connections "+ region.getName()+" >> " + peeringConnectionList.size()); peeringConnectionMap.put(accountId+delimiter+accountName+delimiter+region.getName(), peeringConnectionList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"peeringconnection",e.getMessage()); } } return peeringConnectionMap; }
Example #4
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch VPN gateway. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<VpnGateway>> fetchVPNGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<VpnGateway>> vpnGatewayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"vpngateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VpnGateway> vpnGatewayList = ec2Client.describeVpnGateways().getVpnGateways(); if(!vpnGatewayList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 VPN Gateway "+ region.getName()+" >> " + vpnGatewayList.size()); vpnGatewayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), vpnGatewayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"vpngateway",e.getMessage()); } } return vpnGatewayMap; }
Example #5
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch elastic IP addresses. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<Address>> fetchElasticIPAddresses(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<Address>> elasticIPMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Address> elasticIPList = ec2Client.describeAddresses().getAddresses(); if(!elasticIPList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Elastic IP "+ region.getName()+" >> " + elasticIPList.size()); elasticIPMap.put(accountId+delimiter+accountName+delimiter+region.getName(), elasticIPList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"elasticip",e.getMessage()); } } return elasticIPMap; }
Example #6
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch network ACL. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<NetworkAcl>> fetchNetworkACL(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<NetworkAcl>> networkAclMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<NetworkAcl> networkAclList = ec2Client.describeNetworkAcls().getNetworkAcls(); if(!networkAclList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Network Acl "+ region.getName()+" >> " + networkAclList.size()); networkAclMap.put(accountId+delimiter+accountName+delimiter+region.getName(), networkAclList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"networkacl",e.getMessage()); } } return networkAclMap; }
Example #7
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch route tables. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<RouteTable>> fetchRouteTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<RouteTable>> routeTableMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<RouteTable> routeTableList = ec2Client.describeRouteTables().getRouteTables(); if(!routeTableList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Route table "+ region.getName()+" >> " + routeTableList.size()); routeTableMap.put(accountId+delimiter+accountName+delimiter+region.getName(), routeTableList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"routetable",e.getMessage()); } } return routeTableMap; }
Example #8
Source File: DirectConnectionInventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch direct connections virtual interfaces. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<VirtualInterface>> fetchDirectConnectionsVirtualInterfaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<VirtualInterface>> virtualInterfacesMap = new LinkedHashMap<>(); String expPrefix = "{\"errcode\": \"NO_RES_REG\" ,\"accountId\": \""+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Direct Connections\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ AmazonDirectConnectClient directConnectClient = (AmazonDirectConnectClient) AmazonDirectConnectClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VirtualInterface> virtualInterfacesList = directConnectClient.describeVirtualInterfaces().getVirtualInterfaces(); if(!virtualInterfacesList.isEmpty() ) { log.debug("Account : " + accountId + " Type : Direct Connections "+ region.getName()+" >> " + virtualInterfacesList.size()); virtualInterfacesMap.put(accountId+delimiter+accountName+delimiter+region.getName(), virtualInterfacesList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+"\", \"cause\":\"" +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"virtualinterface",e.getMessage()); } } return virtualInterfacesMap; }
Example #9
Source File: DirectConnectionInventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch direct connections. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<Connection>> fetchDirectConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Connection>> connectionMap = new LinkedHashMap<>(); String expPrefix = "{\"errcode\": \"NO_RES_REG\" ,\"accountId\": \""+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Direct Connections\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ AmazonDirectConnectClient directConnectClient = (AmazonDirectConnectClient) AmazonDirectConnectClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Connection> connectionList = directConnectClient.describeConnections().getConnections(); if(!connectionList.isEmpty() ) { log.debug("Account : " + accountId + " Type : Direct Connections "+ region.getName()+" >> " + connectionList.size()); connectionMap.put(accountId+delimiter+accountName+delimiter+region.getName(), connectionList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+"\", \"cause\":\"" +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"directconnect",e.getMessage()); } } return connectionMap; }
Example #10
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch DHCP options. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<DhcpOptions>> fetchDHCPOptions(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DhcpOptions>> dhcpOptionsMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"dhcpoption\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<DhcpOptions> dhcpOptionsList = ec2Client.describeDhcpOptions().getDhcpOptions(); if(!dhcpOptionsList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 DHCP Options "+ region.getName()+" >> " + dhcpOptionsList.size()); dhcpOptionsMap.put(accountId+delimiter+accountName+delimiter+region.getName(), dhcpOptionsList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"dhcpoption",e.getMessage()); } } return dhcpOptionsMap; }
Example #11
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch customer gateway. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<CustomerGateway>> fetchCustomerGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<CustomerGateway>> customerGatewayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"customergateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<CustomerGateway> customerGatewayList = ec2Client.describeCustomerGateways().getCustomerGateways(); if(!customerGatewayList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Customer Gateway "+ region.getName()+" >> " + customerGatewayList.size()); customerGatewayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), customerGatewayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"customergateway",e.getMessage()); } } return customerGatewayMap; }
Example #12
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch CloudTrails info. * * @param temporaryCredentials the temporary credentials * @param account the account * @return the map */ public static Map<String,List<Trail>> fetchCloudTrails(BasicSessionCredentials temporaryCredentials, String skipRegions,String account, String accountName){ log.info("Fetch CloudTrails info start"); Map<String,List<Trail>> cloudTrails = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+account + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Cloud Trail\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AWSCloudTrail cloudTrailClient = AWSCloudTrailClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeTrailsResult rslt = cloudTrailClient.describeTrails(); List<Trail> trailTemp = rslt.getTrailList(); if(! trailTemp.isEmpty() ){ cloudTrails.put(account+delimiter+accountName+delimiter+region.getName(), trailTemp); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(account,region.getName(),"cloudtrail",e.getMessage()); } } } return cloudTrails; }
Example #13
Source File: ReactCognitoModule.java From react-native-cognito with MIT License | 6 votes |
@ReactMethod public void initCredentialsProvider(String identityPoolId, String token, String region) { RegionUtils regionUtils = new RegionUtils(); Region awsRegion = regionUtils.getRegion(region); cognitoCredentialsProvider = new CognitoCachingCredentialsProvider( mActivityContext.getApplicationContext(), identityPoolId, // awsRegion); Regions.EU_WEST_1); cognitoClient = new CognitoSyncManager( mActivityContext.getApplicationContext(), // awsRegion, Regions.EU_WEST_1, cognitoCredentialsProvider); }
Example #14
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch network intefaces. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<NetworkInterface>> fetchNetworkIntefaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<NetworkInterface>> niMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Network Interface\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeNetworkInterfacesResult descNIRslt = ec2Client.describeNetworkInterfaces(); List<NetworkInterface> niList = descNIRslt.getNetworkInterfaces(); if(!niList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : Network Interface " +region.getName()+" >> " + niList.size()); niMap.put(accountId+delimiter+accountName+delimiter+region.getName(),niList); } } }catch(Exception e){ log.error("Exception fetching Network Interfaces for "+region.getName() + e); log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"eni",e.getMessage()); } } return niMap; }
Example #15
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch security groups. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<SecurityGroup>> fetchSecurityGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ log.info("skipRegionseee" + skipRegions); Map<String,List<SecurityGroup>> secGrpList = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Security Group\" , \"region\":\"" ; log.info("sgregion" + RegionUtils.getRegions().toString()); for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeSecurityGroupsResult rslt = ec2Client.describeSecurityGroups(); List<SecurityGroup> secGrpListTemp = rslt.getSecurityGroups(); if( !secGrpListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Security Group "+region.getName()+" >> " + secGrpListTemp.size()); secGrpList.put(accountId+delimiter+accountName+delimiter+region.getName(),secGrpListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"sg",e.getMessage()); } } return secGrpList; }
Example #16
Source File: KinesisConnectorExecutor.java From amazon-kinesis-connectors with Apache License 2.0 | 6 votes |
/** * Helper method to create Elasticsearch cluster at set correct endpoint. */ private void createElasticsearchCluster() { // Create stack if not already up AmazonCloudFormation cloudFormationClient = new AmazonCloudFormationClient(config.AWS_CREDENTIALS_PROVIDER); cloudFormationClient.setRegion(RegionUtils.getRegion(config.REGION_NAME)); CloudFormationUtils.createStackIfNotExists(cloudFormationClient, config); // Update the elasticsearch endpoint to use endpoint in created cluster AmazonEC2 ec2Client = new AmazonEC2Client(config.AWS_CREDENTIALS_PROVIDER); ec2Client.setRegion(RegionUtils.getRegion(config.REGION_NAME)); config.ELASTICSEARCH_ENDPOINT = EC2Utils.getEndpointForFirstActiveInstanceWithTag(ec2Client, EC2_ELASTICSEARCH_FILTER_NAME, EC2_ELASTICSEARCH_FILTER_VALUE); if (config.ELASTICSEARCH_ENDPOINT == null || config.ELASTICSEARCH_ENDPOINT.isEmpty()) { throw new RuntimeException("Could not find active Elasticsearch endpoint from cluster."); } }
Example #17
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch snapshots. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<Snapshot>> fetchSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Snapshot>> snapShots = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Snapshot\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Snapshot> snapShotsList = ec2Client.describeSnapshots(new DescribeSnapshotsRequest().withOwnerIds(accountId)).getSnapshots();// No need to paginate as all results will be returned if( !snapShotsList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Snapshot " +region.getName() + " >> "+snapShotsList.size()); snapShots.put(accountId+delimiter+accountName+delimiter+region.getName(),snapShotsList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"snapshot",e.getMessage()); } } return snapShots; }
Example #18
Source File: AbstractS3CacheBolt.java From storm-crawler with Apache License 2.0 | 6 votes |
/** Returns an S3 client given the configuration **/ public static AmazonS3Client getS3Client(Map conf) { AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain(); AWSCredentials credentials = provider.getCredentials(); ClientConfiguration config = new ClientConfiguration(); AmazonS3Client client = new AmazonS3Client(credentials, config); String regionName = ConfUtils.getString(conf, REGION); if (StringUtils.isNotBlank(regionName)) { client.setRegion(RegionUtils.getRegion(regionName)); } String endpoint = ConfUtils.getString(conf, ENDPOINT); if (StringUtils.isNotBlank(endpoint)) { client.setEndpoint(endpoint); } return client; }
Example #19
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch VPN connections. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<VpnConnection>> fetchVPNConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<VpnConnection>> vpnConnectionMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"vpnconnection\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VpnConnection> vpnConnectionsList = ec2Client.describeVpnConnections().getVpnConnections(); if(!vpnConnectionsList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 VPN Connections"+ region.getName()+" >> " + vpnConnectionsList.size()); vpnConnectionMap.put(accountId+delimiter+accountName+delimiter+region.getName(), vpnConnectionsList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"vpnconnection",e.getMessage()); } } return vpnConnectionMap; }
Example #20
Source File: AwsRegistry.java From haven-platform with Apache License 2.0 | 6 votes |
/** * AWS Access Key ID [None]: ACESSKEY AWS Secret Access Key [None]: EXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: ENTER */ @Test public void testConnection() { // ClientConfiguration configuration = new ClientConfiguration(); // configuration.set amazonECR.setRegion(RegionUtils.getRegion("us-west-2")); GetAuthorizationTokenResult authorizationToken = amazonECR.getAuthorizationToken(new GetAuthorizationTokenRequest()); log.info("authorizationToken: {}", authorizationToken); List<AuthorizationData> authorizationData = authorizationToken.getAuthorizationData(); log.info("token: {}", authorizationData.get(0).getAuthorizationToken()); log.info("endpoint: {}", authorizationData.get(0).getProxyEndpoint()); // amazonECR.setEndpoint(authorizationData.get(0).getProxyEndpoint()); // BatchGetImageResult batchGetImageResult = amazonECR.batchGetImage(new BatchGetImageRequest()); // log.info("batchGetImageResult {}", batchGetImageResult); }
Example #21
Source File: DynamoDBUtil.java From emr-dynamodb-connector with Apache License 2.0 | 6 votes |
/** * Calculates DynamoDB end-point. * * Algorithm details: * <ol> * <li> Use endpoint in job configuration "dynamodb.endpoint" value if available * <li> Use endpoint from region in job configuration "dynamodb.region" value if available * <li> Use endpoint from region in job configuration "dynamodb.regionid" value if available * <li> Use endpoint from EC2 Metadata of instance if available * <li> If all previous attempts at retrieving endpoint fail, default to us-east-1 endpoint * </ol> * * @param conf Job Configuration * @param region optional preferred region * @return end-point for DynamoDb service */ public static String getDynamoDBEndpoint(Configuration conf, String region) { String endpoint = getValueFromConf(conf, DynamoDBConstants.ENDPOINT); if (Strings.isNullOrEmpty(endpoint)) { if (Strings.isNullOrEmpty(region)) { region = getValueFromConf(conf, DynamoDBConstants.REGION); } if (Strings.isNullOrEmpty(region)) { region = getValueFromConf(conf, DynamoDBConstants.REGION_ID); } if (Strings.isNullOrEmpty(region)) { try { region = EC2MetadataUtils.getEC2InstanceRegion(); } catch (Exception e) { log.warn(String.format("Exception when attempting to get AWS region information. Will " + "ignore and default " + "to %s", DynamoDBConstants.DEFAULT_AWS_REGION), e); } } if (Strings.isNullOrEmpty(region)) { region = DynamoDBConstants.DEFAULT_AWS_REGION; } endpoint = RegionUtils.getRegion(region).getServiceEndpoint(ServiceAbbreviations.Dynamodb); } log.info("Using endpoint for DynamoDB: " + endpoint); return endpoint; }
Example #22
Source File: GenericDynamoDB.java From strongbox with Apache License 2.0 | 6 votes |
public GenericDynamoDB(AmazonDynamoDB client, AWSCredentialsProvider awsCredentials, ClientConfiguration clientConfiguration, SecretsGroupIdentifier groupIdentifier, Class<Entry> clazz, Converters converters, ReadWriteLock readWriteLock) { this.clazz = clazz; buildMappings(); this.converters = converters; this.awsCredentials = awsCredentials; this.clientConfiguration = clientConfiguration; this.client = client; this.region = RegionUtils.getRegion(groupIdentifier.region.getName()); this.readWriteLock = readWriteLock; RegionLocalResourceName resourceName = new RegionLocalResourceName(groupIdentifier); this.tableName = resourceName.toString(); }
Example #23
Source File: BucketLocationHandler.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
public static String getRegionName(@Nullable String location) { if (location == null) { return Regions.US_EAST_1.getName(); } final Region region = RegionUtils.getRegion(location); if (region == null && location.equals("US")) { return Regions.US_EAST_1.getName(); } if (region != null) { return !"US".equals(region.getName()) ? region.getName() : Regions.US_EAST_1.getName(); } else { return location; } }
Example #24
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void descriptorImpl_doFillRegionItems_returnStaticRegionsAndDynamic() { AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class); when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client); when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName("dynamic-region"))); ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); Assert.assertThat(r.size(), Matchers.greaterThan(0)); Assert.assertThat(r.toString(), Matchers.containsString("dynamic-region")); assertEquals(RegionUtils.getRegions().size() + 1, r.size()); }
Example #25
Source File: ClientHelper.java From jobcacher-plugin with MIT License | 5 votes |
private static Region getRegionFromString(String regionName) { // In 0.7, selregion comes from Regions#name Region region = RegionUtils.getRegion(regionName); // In 0.6, selregion comes from Regions#valueOf if (region == null) { region = RegionUtils.getRegion(Regions.valueOf(regionName).getName()); } return region; }
Example #26
Source File: KMSEncryptor.java From strongbox with Apache License 2.0 | 5 votes |
protected KmsMasterKeyProvider getProvider() { if (!prov.isPresent()) { Region region = RegionUtils.getRegion(groupIdentifier.region.getName()); prov = Optional.of(new KmsMasterKeyProvider(awsCredentials, region, transformAndVerifyOrThrow(clientConfiguration), getKeyArn())); } return prov.get(); }
Example #27
Source File: SNSInventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Sets the up. */ @Before public void setUp() { MockitoAnnotations.initMocks(this); mockStatic(RegionUtils.class); when(RegionUtils.getRegions()).thenReturn(getRegions()); }
Example #28
Source File: DynamoDBUtilTest.java From emr-dynamodb-connector with Apache License 2.0 | 5 votes |
@Before public void setUp() { PowerMockito.spy(RegionUtils.class); PowerMockito.mockStatic(EC2MetadataUtils.class); region = mock(Region.class); conf.clear(); }
Example #29
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 5 votes |
private DescribeAvailabilityZonesRequest getDescribeAvailabilityZonesRequest(AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) { DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest(); ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName())); Filter filter = new Filter(); filter.setName("region-name"); Collection<String> list = new ArrayList<>(); list.add(awsRegion.getRegionName()); filter.setValues(list); describeAvailabilityZonesRequest.withFilters(filter); return describeAvailabilityZonesRequest; }
Example #30
Source File: ASGInventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Sets the up. */ @Before public void setUp() { MockitoAnnotations.initMocks(this); mockStatic(RegionUtils.class); when(RegionUtils.getRegions()).thenReturn(getRegions()); }