EC2
Note: if you are running CloudGraph locally you can view the interactive, automatically generated documentation in either GraphQL Playground or Altair by clicking the docs button on the right-hand side of the screen. After reading the below information we highly suggest you use one of these tools to test your queries as they will autocomplete fields for you and let you know if your queries are valid before you even submit them.
You can currently query the following attributes and connections on an AWS EC2 Instance
query { queryawsEc2 { id accountId arn region ami tenancy elasticIps publicDns privateDns monitoring privateIps cpuCoreCount hibernation ebsOptimized ipv4PublicIp instanceType ipv6Addresses placementGroup instanceState sourceDestCheck availabilityZone cpuThreadsPerCore iamInstanceProfile deletionProtection platformDetails keyPair { id name type fingerprint tags { id key value } } dailyCost { cost currency formattedCost } cloudWatchMetricData { lastWeek { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } lastMonth { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } last6Hours { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } last24Hours { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } } primaryNetworkInterface metadataOptions { state # Other fields and connections here... } metadatasecurityGroupIdsOptions securityGroupIds ephemeralBlockDevices { deviceName # Other fields and connections here... } tags { id key value } alb { arn # Other fields and connections here... } asg { arn # Other fields and connections here... } ebs { arn # Other fields and connections here... } eip { arn # Other fields and connections here... } networkInterfaces { arn # Other fields and connections here... } securityGroups { arn # Other fields and connections here... } subnet { arn # Other fields and connections here... } } }
Get data for a single AWS EC2 Instance that you know the ID for:
query { getawsEc2(id: "12345") { arn # Other fields and connections here... } }
Get data for a single EC2 Instance that you know the ARN for:
query { getawsEc2(arn: "arn:12345") { arn # Other fields and connections here... } }
Get data for all of the EC2 Instances in a certain AWS account:
query { queryawsEc2(filter: { accountId: { eq: "12345" } }) { arn # Other fields and connections here... } } # Note that in addition to "accountId" you can # Filter based on any of the following attributes: # id # arn # region # ami # tenancy # elasticIps # publicDns # privateDns # monitoring # privateIps # keyPairName # cpuCoreCount # hibernation # ebsOptimized # ipv4PublicIp # instanceType # ipv6Addresses # placementGroup # instanceState # sourceDestCheck # availabilityZone # cpuThreadsPerCore # iamInstanceProfile # deletionProtection # platformDetails # primaryNetworkInterface # metadatasecurityGroupIdsOptions # securityGroupIds # associatePublicIpAddress # And the following Dgraph filters can also be applied: # has # and # or # not # regexp (regular expressions) # fulltext filters # alloftext # anyoftext
Get data for all of the EC2 Instances that are NOT in a certain AWS account:
query { queryawsEc2(filter: { not: { accountId: { eq: "12345" } } }) { arn # Other fields and connections here... } }
Get data for all of the EC2 Instances that have EIPs in them:
query { queryawsEc2(filter: { has: elasticIps }) { arn # Other fields and connections here... } } # Note that in addition to "elasticIps" you can filter # Using "has" based on any of the following attributes: # id # accountId # arn # region # ami # tenancy # publicDns # privateDns # monitoring # privateIps # keyPairName # cpuCoreCount # hibernation # ebsOptimized # ipv4PublicIp # instanceType # ipv6Addresses # placementGroup # instanceState # sourceDestCheck # availabilityZone # cpuThreadsPerCore # iamInstanceProfile # deletionProtection # platformDetails # dailyCost # primaryNetworkInterface # metadataOptions # metadatasecurityGroupIdsOptions # securityGroupIds # ephemeralBlockDevices # associatePublicIpAddress # tags # alb # asg # ebs # eip # networkInterfaces # securityGroups # subnet
Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the EC2 Instances that have ALBs AND a Placement Group OR that do not have EIPs. Note that you can use has, and, not, or completely independently of each other:
query { queryawsEc2( filter: { has: alb and: { has: placementGroup } or: { not: { has: eip } } } ) { arn # Other fields and connections here... } }
You may also filter using a regex when filtering on a string field like, privateIps if you want to look for a value that matches say, 10.0.0.0:
query { queryawsEc2(filter: { privateIps: { regexp: "/.*10.1.24.33.*/" } }) { arn # Other fields and connections here... } }
You can order the results you get back either asc or desc depending on your preference:
query { queryawsEc2(order: { desc: privateIps }) { privateIps # Other fields and connections here... } } # Note that in addition to "privateIps" you can filter # Using "asc" or "desc" based on any of the following attributes: # id # accountId # arn # region # ami # tenancy # elasticIps # publicDns # privateDns # monitoring # cpuCoreCount # hibernation # ebsOptimized # ipv4PublicIp # instanceType # placementGroup # instanceState # sourceDestCheck # availabilityZone # cpuThreadsPerCore # iamInstanceProfile # deletionProtection # platformDetails # primaryNetworkInterface # associatePublicIpAddress
Only select and return the first two EC2 Instances that are found:
query { queryawsEc2(first: 2, order: { desc: privateIps }) { privateIps # Other fields and connections here... } }
Only select and return the first two EC2 Instances that are found, but offset by one so EC2 Instances two & three are returned:
query { queryawsEc2(first: 2, order: { desc: privateIps }, offset: 1) { privateIps # Other fields and connections here... } }
Count the number of EC2 Instances across all scanned AWS accounts:
query { aggregateawsEc2 { count # Other fields and connections here... } } # Note that in addition to "count" you can request the # Following min and max values based on attributes of your EC2 Instances: # idMin # idMax # accountIdMin # accountIdMax # arnMin # arnMax # regionMin # regionMax # amiMin # amiMax # tenancyMin # tenancyMax # elasticIpsMin # elasticIpsMax # publicDnsMin # publicDnsMax # privateDnsMin # privateDnsMax # monitoringMin # monitoringMax # privateIpsMin # privateIpsMax # cpuCoreCountMin # cpuCoreCountMax # cpuCoreCountSum # cpuCoreCountAvg # hibernationMin # hibernationMax # ebsOptimizedMin # ebsOptimizedMax # ipv4PublicIpMin # ipv4PublicIpMax # instanceTypeMin # instanceTypeMax # placementGroupMin # placementGroupMax # instanceStateMin # instanceStateMax # sourceDestCheckMin # sourceDestCheckMax # availabilityZoneMin # availabilityZoneMax # cpuThreadsPerCoreMin # cpuThreadsPerCoreMax # cpuThreadsPerCoreSum # cpuThreadsPerCoreAvg # iamInstanceProfileMin # iamInstanceProfileMax # deletionProtectionMin # deletionProtectionMax # platformDetailsMin # platformDetailsMax # primaryNetworkInterfaceMin # primaryNetworkInterfaceMax # associatePublicIpAddressMin # associatePublicIpAddressMax
Count the number of EC2 Instances in a single account. Note that you can apply all of the same filters that are listed above to aggregate queries:
query { aggregateawsEc2(filter: { accountId: { eq: "12345" } }) { count # Other fields and connections here... } }
Find all the burstable T series instances:
query { queryawsEc2(filter: { instanceType: { regexp: "/^t.*/" } }) { id arn availabilityZone instanceType } }
For each M5 EC2 Instance in the us-east-1 region for the AWS Account, 12345 get the ARN, daily cost, and EBS Volume that is its boot disk:
query { queryawsEc2( filter: { accountId: { eq: "12345" } region: { eq: "us-east-1" } instanceType: { regexp: "/^m5a*/" } } ) { arn dailyCost { cost currency formattedCost } ebs(filter: { isBootDisk: true }, first: 1) { arn } } }
Find all of the EC2 Instances that have a tag of Environment:Production for a single AWS Account:
query { queryawsTag( filter: { key: { eq: "Environment" }, value: { eq: "Production" } } ) { ec2Instance(filter: { accountId: { eq: "12345" } }) { arn # Other fields and connections here... } } }
With CloudGraph you can run multiple queries at the same time so you can combine the above two queries if you like:
query { queryawsEc2( filter: { accountId: { eq: "12345" } region: { eq: "us-east-1" } instanceType: { regexp: "/^m5a*/" } } ) { arn dailyCost { cost currency formattedCost } ebs(filter: { isBootDisk: true }, first: 1) { arn } } queryawsTag( filter: { key: { eq: "Environment" }, value: { eq: "Production" } } ) { ec2Instance(filter: { accountId: { eq: "12345" } }) { arn # Other fields and connections here... } } }
Putting it all together; get all data for all EC2 Instances across all regions for all scanned AWS accounts in a single query. For the purposes of this example we will only get direct children of the EC2 Instances but if you want to it's easy to go from say, EC2 Instance -> Subnet -> VPC...etc:
query { queryawsEc2 { id accountId arn region ami tenancy elasticIps publicDns privateDns monitoring privateIps cpuCoreCount hibernation ebsOptimized ipv4PublicIp instanceType ipv6Addresses placementGroup instanceState sourceDestCheck availabilityZone cpuThreadsPerCore iamInstanceProfile deletionProtection platformDetails keyPair { id name type fingerprint tags { id key value } } dailyCost { cost currency formattedCost } cloudWatchMetricData { lastWeek { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } lastMonth { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } last6Hours { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } last24Hours { cpuUtilizationAverage networkInAverage networkOutAverage networkPacketsInAverage networkPacketsOutAverage statusCheckFailedSum statusCheckFailedInstanceSum statusCheckFailedSystemSum diskReadOpsAverage diskWriteOpsAverage diskReadBytesAverage diskWriteBytesAverage } } primaryNetworkInterface metadataOptions { state # Other fields and connections here... } metadatasecurityGroupIdsOptions securityGroupIds ephemeralBlockDevices { deviceName # Other fields and connections here... } tags { id key value } alb { id accountId arn dnsName scheme type subnets hostedZone defaultVpc ipAddressType idleTimeout deletionProtection http2 accessLogsEnabled dropInvalidHeaderFields createdAt status tags { id key value } securityGroups { arn # Other fields and connections here... } ec2Instance { arn # Other fields and connections here... } vpc { arn # Other fields and connections here... } route53Record { id # Other fields and connections here... } listeners { arn # Other fields and connections here... } subnet { arn # Other fields and connections here... } } asg { id accountId arn name region launchConfigurationName launchTemplateId launchTemplateName launchTemplateVersion mixedInstancesPolicy { launchTemplateId # Other fields and connections here... } minSize maxSize desiredCapacity predictedCapacity cooldown availabilityZones loadBalancerNames targetGroupARNs healthCheckType healthCheckGracePeriod ec2InstanceIds suspendedProcesses { id # Other fields and connections here... } placementGroup vpcZoneIdentifier enabledMetrics { id # Other fields and connections here... } status terminationPolicies newInstancesProtectedFromScaleIn serviceLinkedRoleARN maxInstanceLifetime capacityRebalanceEnabled warmPoolConfigMaxGroupPreparedCapacity warmPoolConfigMinSize warmPoolConfigPoolState warmPoolConfigStatus warmPoolSize context tags { id key value } launchConfiguration { imageId # Other fields and connections here... } ec2Instance { arn # Other fields and connections here... } securityGroups { arn # Other fields and connections here... } ebs { arn # Other fields and connections here... } subnet { arn # Other fields and connections here... } } ebs { id accountId arn attachments { id # Other fields and connections here... } iops size state created snapshot encrypted isBootDisk volumeType availabilityZone multiAttachEnabled tags { id key value } ec2Instance { arn # Other fields and connections here... } asg { arn # Other fields and connections here... } } eip { id accountId arn tags { id key value } vpc domain publicIp privateIp instanceId publicIpv4Pool networkInterfaceId ec2InstanceAssociationId networkInterfaceOwnerId networkBorderGroup customerOwnedIp customerOwnedIpv4Pool vpcs { arn # Other fields and connections here... } ec2Instance { arn # Other fields and connections here... } networkInterface { arn # Other fields and connections here... } } networkInterfaces { id accountId arn subnetId macAddress description availabilityZone status vpcId interfaceType securityGroups privateDnsName privateIps attachment { id # Other fields and connections here... } tags { id key value } ec2Instance { arn # Other fields and connections here... } eip { arn # Other fields and connections here... } natGateway { arn # Other fields and connections here... } subnet { arn # Other fields and connections here... } vpc { arn # Other fields and connections here... } } securityGroups { id accountId arn name vpcId description tags { id key value } owner default inboundRules { id # Other fields and connections here... } outboundRules { id # Other fields and connections here... } inboundRuleCount outboundRuleCount alb { arn # Other fields and connections here... } lambda { arn # Other fields and connections here... } elb { arn # Other fields and connections here... } ec2Instance { arn # Other fields and connections here... } asg { arn # Other fields and connections here... } rdsCluster { arn # Other fields and connections here... } rdsDbInstance { arn # Other fields and connections here... } } subnet { id accountId arn autoAssignPublicIpv4Address autoAssignPublicIpv6Address availabilityZone availableIpV4Addresses defaultForAz ipV4Cidr ipV6Cidr state tags { id key value } alb { arn # Other fields and connections here... } asg { arn # Other fields and connections here... } ec2Instance { arn # Other fields and connections here... } elb { arn # Other fields and connections here... } lambda { arn # Other fields and connections here... } natGateway { arn # Other fields and connections here... } networkInterface { arn # Other fields and connections here... } routeTable { arn # Other fields and connections here... } vpc { arn # Other fields and connections here... } rdsDbInstance { arn # Other fields and connections here... } } } }

