website logo
HomeGithubSlack
⌘K
Overview
Quick Start
Supported Services
Running CloudGraph in EKS
Compliance
Rules Engine
AWS
Querying AWS Data
AWS Policy Packs
Billing Data
Services
Azure
Querying Azure Data
Azure Policy Packs
Services
GCP
Querying GCP Data
GCP Policy Packs
Services
K8s
Querying Kubernetes Data
Services
Docs powered by archbee 

VPC

20min

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.

Overview

You can currently query the following attributes and connections on an AWS VPC

GraphQL
|
query {
  queryawsVpc {
    accountId
    arn
    defaultVpc
    dhcpOptionsSet
    enableDnsHostnames
    enableDnsSupport
    id
    instanceTenancy
    ipV4Cidr
    ipV6Cidr
    state
    alb {
      arn
      # Other fields and connections here...
    }
    eip {
      arn
      # Other fields and connections here...
    }
    elb {
      arn
      # Other fields and connections here...
    }
    igw {
      arn
      # Other fields and connections here...
    }
    tags {
      id
      key
      value
    }
    nacl {
      arn
      # Other fields and connections here...
    }
    lambda {
      arn
      # Other fields and connections here...
    }
    subnet {
      arn
      # Other fields and connections here...
    }
    natGateway {
      arn
      # Other fields and connections here...
    }
    routeTable {
      arn
      # Other fields and connections here...
    }
    rdsDbInstance {
      # Other fields and connections here...
      arn
    }
    route53HostedZone {
      # Other fields and connections here...
      arn
    }
  }
}


Filtering

Get data for a single AWS VPC that you know the ID for:

GraphQL
|
query {
  getawsVpc(id: "12345") {
    arn
    # Other fields and connections here...
  }
}


Get data for a single VPC that you know the ARN for:

GraphQL
|
query {
  getawsVpc(arn: "arn:12345") {
    arn
    # Other fields and connections here...
  }
}


Get data for all of the VPCs in a certain AWS account:

GraphQL
|
query {
  queryawsVpc(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:

# arn
# defaultVpc
# dhcpOptionsSet
# enableDnsHostnames
# enableDnsSupport
# id
# instanceTenancy
# ipV4Cidr
# ipV6Cidr
# state

# 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 VPCs that are NOT in a certain AWS account:

GraphQL
|
query {
  queryawsVpc(filter: { not: { accountId: { eq: "12345" } } }) {
    arn
    # Other fields and connections here...
  }
}


Advanced Filtering

Get data for all of the VPCs that have Lambdas in them:

GraphQL
|
query {
  queryawsVpc(filter: { has: lambda }) {
    arn
    # Other fields and connections here...
  }
}

# Note that in addition to "lambda" you can filter
# Using "has" based on any of the following attributes:

# accountId
# arn
# defaultVpc
# dhcpOptionsSet
# enableDnsHostnames
# enableDnsSupport
# id
# instanceTenancy
# ipV4Cidr
# ipV6Cidr
# state
# tags
# alb
# eip
# elb
# igw
# nacl
# natGateway
# networkInterface
# rdsDbInstance
# route53HostedZone
# routeTable
# subnet


Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the VPCs that have Lambdas AND RDS DB Instances in them OR that do not have IGWs in them. Note that you can use has, and, not, or completely independently of each other:

GraphQL
|
query {
  queryawsVpc(
    filter: {
      has: lambda
      and: { has: rdsDbInstance }
      or: { not: { has: igw } }
    }
  ) {
    arn
    # Other fields and connections here...
  }
}


You may also filter using a regex when filtering on a string field like, ipV4Cidr if you want to look for a value that matches say, 10.0.0.0:

GraphQL
|
query {
  queryawsVpc(filter: { ipV4Cidr: { regexp: "/.*10.0.0.0.*/" } }) {
    arn
    # Other fields and connections here...
  }
}


Ordering

You can order the results you get back either asc or desc depending on your preference:

GraphQL
|
query {
  queryawsVpc(order: { desc: ipV4Cidr }) {
    ipV4Cidr
    # Other fields and connections here...
  }
}

# Note that in addition to "ipV4Cidr" you can filter
# Using "asc" or "desc" based on any of the following attributes:

# arn
# accountId
# dhcpOptionsSet
# id
# instanceTenancy
# ipV6Cidr
# state


Only select and return the first two VPCs that are found:

GraphQL
|
query {
  queryawsVpc(first: 2, order: { desc: ipV4Cidr }) {
    ipV4Cidr
    # Other fields and connections here...
  }
}


Only select and return the first two VPCs that are found, but offset by one so VPCs two & three are returned:

GraphQL
|
query {
  queryawsVpc(first: 2, order: { desc: ipV4Cidr }, offset: 1) {
    arn
    # Other fields and connections here...
  }
}


Aggregation

Count the number of VPCs across all scanned AWS accounts:

GraphQL
|
query {
  aggregateawsVpc {
    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 VPCs:

# count
# accountIdMin
# accountIdMax
# arnMin
# arnMax
# dhcpOptionsSetMin
# dhcpOptionsSetMax
# idMin
# idMax
# instanceTenancyMin
# instanceTenancyMax
# ipV4CidrMin
# ipV4CidrMax
# ipV6CidrMin
# ipV6CidrMax
# stateMin
# stateMax


Count the number of VPCs in a single account. Note that you can apply all of the same filters that are listed above to aggregate queries:

GraphQL
|
query {
  aggregateawsVpc(filter: { accountId: { eq: "12345" } }) {
    count
    # Other fields and connections here...
  }
}


Examples

Find the default VPCs across all your scanned AWS Accounts to see if they are being used:

GraphQL
|
query {
  queryawsVpc(filter: { defaultVpc: true }) {
    arn
    # Other fields and connections here...
  }
}


Find all of the VPCs that have a tag of Environment:Production for a single AWS Account:

GraphQL
|
query {
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    vpc(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:

GraphQL
|
query {
  queryawsVpc(filter: { defaultVpc: true }) {
    arn
    # Other fields and connections here...
  }
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    vpc(filter: { accountId: { eq: "12345" } }) {
      arn
      # Other fields and connections here...
    }
  }
}


When you think, "in terms of a graph", you can do almost anything with CloudGraph. Say for example that you want to know what Lamba functions don't belong to a VPC (i.e. they don't leverage VPC networking). Because CloudGraph connects all resources that have relationships, such as VPC parents to their Lambda children, you are able to answer this question easily. Simply check to see what lambda functions the VPC is "connected" to, and compare that against the list of all lambda functions like so:

GraphQL
|
query {
  queryawsVpc(filter: { arn: { eq: "arn:12345" } }) {
    arn
    lambda {
      arn
    }
  }
  queryawsLambda {
    arn
  }
}

# To be fair you could just query lambda directly and
# See which functions don't return the `ARN` of a VPC:

# query {
#   queryawsLambda {
#     arn
#     vpc {
#       arn
#     }
#   }
# }


Kitchen Sink

Putting it all together; get all data for all VPCs 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 VPCs but if you want to it's easy to go from say, VPC -> ALB -> EC2 -> EBS...etc:

GraphQL
|
query {
  queryawsVpc {
    accountId
    arn
    defaultVpc
    dhcpOptionsSet
    enableDnsHostnames
    enableDnsSupport
    id
    instanceTenancy
    ipV4Cidr
    ipV6Cidr
    state
    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...
      }
    }
    eip {
      arn
      id
      accountId
      arn
      vpc
      domain
      publicIp
      privateIp
      instanceId
      publicIpv4Pool
      networkInterfaceId
      ec2InstanceAssociationId
      networkInterfaceOwnerId
      networkBorderGroup
      customerOwnedIp
      customerOwnedIpv4Pool
      tags {
        id
        key
        value
      }
      vpcs {
        arn
        # Other fields and connections here...
      }
      ec2Instance {
        arn
        # Other fields and connections here...
      }
      networkInterface {
        arn
        # Other fields and connections here...
      }
    }
    elb {
      id
      accountId
      arn
      dnsName
      hostedZone
      createdAt
      type
      status
      scheme
      vpcId
      sourceSecurityGroup {
        groupName
        # Other fields and connections here...
      }
      securityGroupsIds
      subnets
      accessLogs
      crossZoneLoadBalancing
      idleTimeout
      instances {
        id
        # Other fields and connections here...
      }
      healthCheck {
        target
        # Other fields and connections here...
      }
      listeners {
        id
        # Other fields and connections here...
      }
      tags {
        id
        key
        value
      }
      cloudfrontDistribution {
        arn
        # Other fields and connections here...
      }
      securityGroups {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
      route53Record {
        id
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
    }
    igw {
      accountId
      arn
      id
      owner
      attachments {
        vpcId
        # Other fields and connections here...
      }
      tags {
        id
        key
        value
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
    tags {
      id
      key
      value
    }
    nacl {
      id
      arn
      accountId
      default
      inboundRules {
        id
        # Other fields and connections here...
      }
      outboundRules {
        id
        # Other fields and connections here...
      }
      associatedSubnets {
        id
        # Other fields and connections here...
      }
      region
      tags {
        id
        key
        value
      }
      vpc {
        arn
        # Other fields and connections here...
      }
      vpcId
    }
    lambda {
      id
      accountId
      arn
      description
      handler
      kmsKeyArn
      lastModified
      memorySize
      reservedConcurrentExecutions
      role
      runtime
      sourceCodeSize
      timeout
      tracingConfig
      version
      environmentVariables {
        id
        key
        value
      }
      tags {
        id
        key
        value
      }
      kms {
        arn
        # Other fields and connections here...
      }
      securityGroups {
        arn
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
      cognitoUserPool {
        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...
      }
    }
    natGateway {
      id
      accountId
      arn
      state
      createTime
      dailyCost {
        cost
        formattedCost
        currency
      }
      tags {
        id
        key
        value
      }
      networkInterface {
        arn
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
    routeTable {
      id
      accountId
      arn
      vpcId
      routes {
        id
        # Other fields and connections here...
      }
      mainRouteTable
      explicitlyAssociatedWithSubnets
      subnetAssociations
      tags {
        id
        key
        value
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
    rdsDbInstance {
      id
      accountId
      arn
      name
      port
      address
      hostedZoneId
      username
      resourceId
      engine
      engineVersion
      createdTime
      copyTagsToSnapshot
      deletionProtection
      dBInstanceIdentifier
      performanceInsightsEnabled
      autoMinorVersionUpgrade
      iamDbAuthenticationEnabled
      optionsGroups
      parameterGroup
      storageType
      instanceClass
      allocatedStorage
      multiAZ
      subnetGroup
      availabilityZone
      publiclyAccessible
      certificateAuthority
      status
      failoverPriority
      kmsKey
      encrypted
      tags {
        id
        key
        value
      }
      cluster {
        arn
        # Other fields and connections here...
      }
      securityGroups {
        arn
        # Other fields and connections here...
      }
      subnet {
        arn
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
    route53HostedZone {
      id
      accountId
      arn
      name
      comment
      delegationSetId
      nameServers
      route53Record {
        id
        # Other fields and connections here...
      }
      vpc {
        arn
        # Other fields and connections here...
      }
    }
  }
}


References

AWS VPC documentation

Dgraph documentation on querying

Updated 03 Mar 2023
Did this page help you?
Yes
No
PREVIOUS
Transit Gateway Attachment
NEXT
VPN Connection
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Examples
Kitchen Sink
References