Java Code Examples for com.amazonaws.regions.Region#isServiceSupported()
The following examples show how to use
com.amazonaws.regions.Region#isServiceSupported() .
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 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 2
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch EFS 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<EfsVH>> fetchEFSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ AmazonElasticFileSystem efsClient ; Map<String,List<EfsVH>> efsMap = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"EFS\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ efsClient = AmazonElasticFileSystemClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<FileSystemDescription> efsListTemp = new ArrayList<>(); String nextToken = null; DescribeFileSystemsResult descRslt ; do{ descRslt = efsClient.describeFileSystems(new DescribeFileSystemsRequest().withMarker(nextToken)); efsListTemp.addAll(descRslt.getFileSystems()); nextToken = descRslt.getNextMarker(); }while(nextToken!=null); List<EfsVH> efsList = new ArrayList<>(); for(FileSystemDescription efs :efsListTemp ){ efsList.add( new EfsVH(efs, efsClient.describeTags(new DescribeTagsRequest().withFileSystemId(efs.getFileSystemId())).getTags())); } if(! efsList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EFS "+region.getName() + " >> "+efsList.size()); efsMap.put(accountId+delimiter+accountName+delimiter+region.getName(), efsList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonElasticFileSystem.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"efs",e.getMessage()); } } } return efsMap; }
Example 3
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch EMR 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<Cluster>> fetchEMRInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<Cluster>> clusterList = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"EMR\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonElasticMapReduce emrClient = AmazonElasticMapReduceClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<ClusterSummary> clusters = new ArrayList<>(); String marker = null; ListClustersResult clusterResult ; do{ clusterResult = emrClient.listClusters(new ListClustersRequest().withMarker(marker)); clusters.addAll(clusterResult.getClusters()); marker = clusterResult.getMarker(); }while(marker!=null); List<Cluster> clustersList = new ArrayList<>(); clusters.forEach(cluster -> { DescribeClusterResult descClstrRslt = emrClient.describeCluster(new DescribeClusterRequest().withClusterId(cluster.getId())); clustersList.add(descClstrRslt.getCluster()); }); if( !clustersList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : EMR "+region.getName() + " >> "+clustersList.size()); clusterList.put(accountId+delimiter+accountName+delimiter+region.getName(),clustersList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonElasticMapReduce.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"emr",e.getMessage()); } } } return clusterList; }
Example 4
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDS cluster 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<DBClusterVH>> fetchRDSClusterInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBClusterVH>> rdsMap = new LinkedHashMap<>(); AmazonRDS rdsClient ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Cluster\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeDBClustersResult rslt ; String nextMarker = null; List<DBClusterVH> rdsList = new ArrayList<>(); do{ rslt = rdsClient.describeDBClusters( new DescribeDBClustersRequest().withMarker(nextMarker)); List<DBCluster> rdsListTemp = rslt.getDBClusters(); for(DBCluster cluster : rdsListTemp){ DBClusterVH vh = new DBClusterVH(cluster,rdsClient.listTagsForResource(new ListTagsForResourceRequest(). withResourceName(cluster.getDBClusterArn())). getTagList()); rdsList.add(vh); } nextMarker = rslt.getMarker(); }while(nextMarker!=null); if( !rdsList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Cluster "+region.getName() + " >> "+rdsList.size()); rdsMap.put(accountId+delimiter+accountName+delimiter+region.getName(), rdsList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdscluster",e.getMessage()); } } } return rdsMap; }
Example 5
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDSDB 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<DBSnapshot>> fetchRDSDBSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBSnapshot>> snapshots = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Snapshot\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonRDS rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeDBSnapshotsResult rslt ; List<DBSnapshot> snapshotsTemp = new ArrayList<>(); String marker = null; do{ rslt = rdsClient.describeDBSnapshots(new DescribeDBSnapshotsRequest().withIncludePublic(false).withIncludeShared(false).withMarker(marker)); snapshotsTemp.addAll(rslt.getDBSnapshots()); marker = rslt.getMarker(); }while(marker!=null); if(! snapshotsTemp.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Snapshot" +region.getName() + " >> "+snapshotsTemp.size()); snapshots.put(accountId+delimiter+accountName+delimiter+region.getName(), snapshotsTemp); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdssnapshot",e.getMessage()); } } } return snapshots; }
Example 6
Source File: SQSTriggerQueue.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 5 votes |
public ListBoxModel doFillRegionItems() { ListBoxModel items = new ListBoxModel(); items.add("", ""); for (Regions region : Regions.values()) { Region r = Region.getRegion(region); if (r.isServiceSupported(AmazonSQS.ENDPOINT_PREFIX) && r.isServiceSupported("codecommit")) { items.add(region.getName(), region.name()); } } return items; }
Example 7
Source File: KinesisInventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
public static Map<String,List<VideoStreamVH>> fetchVideoStreamInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<VideoStreamVH>> videoStream = new LinkedHashMap<>(); AmazonKinesisVideo amazonKinesisVideo; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource\" ,\"type\": \"videoStream\" " ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName()) && region.isServiceSupported(AmazonKinesisVideo.ENDPOINT_PREFIX)){ amazonKinesisVideo = AmazonKinesisVideoClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<StreamInfo> videoStreamListTemp = new ArrayList<>(); com.amazonaws.services.kinesisvideo.model.ListStreamsResult listStreamsResult; String nextToken = null; do{ listStreamsResult = amazonKinesisVideo.listStreams(new ListStreamsRequest().withNextToken(nextToken)); videoStreamListTemp.addAll(listStreamsResult.getStreamInfoList()); nextToken = listStreamsResult.getNextToken(); }while(nextToken!=null); List<VideoStreamVH> videoStreamList = new ArrayList<>(); for(StreamInfo streamInfo : videoStreamListTemp) { List<Attribute> tags = new ArrayList<>(); for(Entry<String, String> entry: amazonKinesisVideo.listTagsForStream(new com.amazonaws.services.kinesisvideo.model.ListTagsForStreamRequest() .withStreamARN(streamInfo.getStreamARN())).getTags().entrySet()) { tags.add(new Attribute(entry.getKey(), entry.getValue())); } videoStreamList.add(new VideoStreamVH(streamInfo,tags)); } if( !videoStreamList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : VideoStream "+region.getName() + " >> "+videoStreamList.size()); videoStream.put(accountId+delimiter+accountName+delimiter+region.getName(),videoStreamList); } } } catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId, region.getName(),"videoStream",e.getMessage()); } } return videoStream; }
Example 8
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch dynamo DB tables. * * @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<DynamoVH>> fetchDynamoDBTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DynamoVH>> dynamodbtables = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"DynamoDB\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonDynamoDB awsClient= AmazonDynamoDBClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String marker = null; List<String> tables = new ArrayList<>(); ListTablesResult listTableResult; do{ listTableResult = awsClient.listTables(new ListTablesRequest().withExclusiveStartTableName(marker)); marker = listTableResult.getLastEvaluatedTableName(); tables.addAll(listTableResult.getTableNames()); }while(marker!=null); List<DynamoVH> dynamodbtablesTemp = new ArrayList<>(); tables.parallelStream().forEach(tblName -> { TableDescription table = awsClient.describeTable(tblName).getTable(); List<com.amazonaws.services.dynamodbv2.model.Tag> tags = awsClient.listTagsOfResource(new ListTagsOfResourceRequest().withResourceArn( table.getTableArn())).getTags(); synchronized (dynamodbtablesTemp) { dynamodbtablesTemp.add(new DynamoVH(table,tags)); } }); if(!dynamodbtablesTemp.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : DynamoDB "+region.getName() + " >> "+dynamodbtablesTemp.size()); dynamodbtables.put(accountId+delimiter+accountName+delimiter+region.getName(), dynamodbtablesTemp); } } }catch(Exception e){ if(region.isServiceSupported(AmazonDynamoDB.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"dynamodb",e.getMessage()); } } } return dynamodbtables; }
Example 9
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch lambda 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<LambdaVH>> fetchLambdaInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<LambdaVH>> functions = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Lambda\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AWSLambda lamdaClient = AWSLambdaClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); ListFunctionsResult listFnRslt ; List<FunctionConfiguration> functionsTemp ; List<LambdaVH> lambdaList = new ArrayList<>(); String nextMarker = null; do{ listFnRslt = lamdaClient.listFunctions(new ListFunctionsRequest().withMarker(nextMarker)); functionsTemp = listFnRslt.getFunctions(); if( !functionsTemp.isEmpty() ) { functionsTemp.forEach( function -> { Map<String,String> tags = lamdaClient.listTags(new ListTagsRequest().withResource(function.getFunctionArn())).getTags(); LambdaVH lambda = new LambdaVH(function, tags); lambdaList.add(lambda); }); } nextMarker = listFnRslt.getNextMarker(); }while(nextMarker!=null); if( !lambdaList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Lambda " +region.getName() + " >> "+lambdaList.size()); functions.put(accountId+delimiter+accountName+delimiter+region.getName(),lambdaList); } } }catch(Exception e){ if(region.isServiceSupported(AWSLambda.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"lambda",e.getMessage()); } } } return functions ; }
Example 10
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch RDS instance 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<DBInstanceVH>> fetchRDSInstanceInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBInstanceVH>> dbInstMap = new LinkedHashMap<>(); AmazonRDS rdsClient ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Instance\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String nextMarker = null; DescribeDBInstancesResult rslt; List<DBInstanceVH> dbInstList = new ArrayList<>(); do{ rslt = rdsClient.describeDBInstances(new DescribeDBInstancesRequest().withMarker(nextMarker)); List<DBInstance> dbInstListTemp = rslt.getDBInstances(); for(DBInstance db : dbInstListTemp){ DBInstanceVH vh = new DBInstanceVH(db, rdsClient.listTagsForResource(new ListTagsForResourceRequest(). withResourceName(db.getDBInstanceArn())). getTagList(), db.getDBSubnetGroup().getSubnets().stream().map(subnet -> subnet.getSubnetIdentifier()).collect(Collectors.joining(",")), db.getVpcSecurityGroups().stream().map(group->group.getVpcSecurityGroupId()+":"+group.getStatus()).collect(Collectors.joining(",")) ); dbInstList.add(vh); } nextMarker = rslt.getMarker(); }while(nextMarker!=null); if(! dbInstList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Instance" +region.getName() + " >> "+dbInstList.size()); dbInstMap.put(accountId+delimiter+accountName+delimiter+region.getName(), dbInstList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdsdb",e.getMessage()); } } } return dbInstMap; }
Example 11
Source File: EC2Api.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
/** * Derive EC2 API endpoint. If <code>endpoint</code> parameter not empty will use * it as first priority, otherwise will try to find region in {@link RegionUtils} by <code>regionName</code> * and use endpoint from it, if not available will generate endpoint as string and check if * region name looks like China <code>cn-</code> prefix. * <p> * Implementation details * <p> * {@link RegionUtils} is static information, and to get new region required to be updated, * as it's not possible too fast as you need to check new version of lib, moreover new version of lib * could be pointed to new version of Jenkins which is not a case for our plugin as some of installation * still on <code>1.6.x</code> * <p> * For example latest AWS SDK lib depends on Jackson2 plugin which starting from version <code>2.8.7.0</code> * require Jenkins at least <code>2.60</code> https://plugins.jenkins.io/jackson2-api * <p> * List of all AWS endpoints * https://docs.aws.amazon.com/general/latest/gr/rande.html * * @param regionName like us-east-1 not a airport code, could be <code>null</code> * @param endpoint custom endpoint could be <code>null</code> * @return <code>null</code> or actual endpoint */ @Nullable public String getEndpoint(@Nullable final String regionName, @Nullable final String endpoint) { if (StringUtils.isNotEmpty(endpoint)) { return endpoint; } else if (StringUtils.isNotEmpty(regionName)) { final Region region = RegionUtils.getRegion(regionName); if (region != null && region.isServiceSupported(endpoint)) { return region.getServiceEndpoint(endpoint); } else { final String domain = regionName.startsWith("cn-") ? "amazonaws.com.cn" : "amazonaws.com"; return "https://ec2." + regionName + "." + domain; } } else { return null; } }