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 

IAM Instance Profile

18min

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 IAM Instance Profile

GraphQL
|
query { 
  queryawsIamInstanceProfile {
    id
    arn
    accountId
    name
    path
    createDate
    tags {
      id
      key
      value
    }
    iamRole {
      arn
      # Other fields and connections here...
    }
  }
}


Filtering

Get data for a single AWS IAM Instance Profile that you know the ID for:

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


Get data for all of the IAM Instance Profiles in a certain AWS account:

GraphQL
|
query {
  queryawsIamInstanceProfile(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
# path
# name
# createDate

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

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


Advanced Filtering

Get data for all of the IAM Instance Profiles that have IAM Role:

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

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

# id
# arn
# path
# name
# createDate
# tags
# iamRole


Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the IAM Instance Profiles that have IAM Role OR that do not have Tags. Note that you can use has, and, not, or completely independently of each other:

GraphQL
|
query {
  queryawsIamInstanceProfile(
    filter: {
      has: iamRole
      or: { not: { has: tags } }
    }
  ) {
    arn
    # Other fields and connections here...
  }
}


You may also filter using a regex when filtering on a string field like, name if you want to look for a value that contains the word, production (case insensitive):

GraphQL
|
query {
  queryawsIamInstanceProfile(filter: { name: { regexp: "/.*production.*/i" } }) {
    arn
    name
    # Other fields and connections here...
  }
}


Ordering

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

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

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

# id
# arn
# path
# name
# createDate


Only select and return the first two IAM Instance Profiles that are found:

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


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

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


Aggregation

Count the number of IAM Instance Profiles across all scanned AWS accounts:

GraphQL
|
query {
  aggregateawsIamInstanceProfile {
    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 IAM Instance Profiles:

# idMin
# idMax
# arnMin
# arnMax
# accountIdMin
# accountIdMax
# pathMin
# pathMax
# nameMin
# nameMax
# createDateMin
# createDateMax


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

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


Examples

Find all the IAM Instance Profiles that for your dev env:

GraphQL
|
query {
  queryawsIamInstanceProfile(filter: { name: { regexp: "/.*dev.*/i" } }) {
    arn
    name
    # Other fields and connections here...
  }
}


Find all the IAM Instance Profiless in account 12345:

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


Find all of the IAM Instance Profiless that have a tag of Environment:Production for a single AWS Account:

GraphQL
|
query {
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    iamInstanceProfiles(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 {
  queryawsIamInstanceProfile(filter: { accountId: { eq: "12345" } }) {
    arn
    # Other fields and connections here...
  }
  queryawsTag(
    filter: { key: { eq: "Environment" }, value: { eq: "Production" } }
  ) {
    iamInstanceProfiles(filter: { accountId: { eq: "12345" } }) {
      arn
      # Other fields and connections here...
    }
  }
}


Kitchen Sink

Putting it all together; get all data for all IAM Instance Profiless 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 IAM Instance Profiless but if you want to it's easy to go from say, an IAM Instance Profile -> IAM Role -> IAM Attached Policies ...etc:

GraphQL
|
query { 
  queryawsIamInstanceProfile {
    id
    arn
    accountId
    name
    path
    createDate
    tags {
      id
      key
      value
    }
    iamRole {
      id
      arn
      accountId
      name
      path
      assumeRolePolicy {
        id
        version
        statement {
          id
          action
          condition {
            id
            operator
            key
            value
          }
          effect
          principal {
            id
            key
            value
          }
          resource
          conditionAggregate {
            count
            operatorMin
            operatorMax
            keyMin
            keyMax
          }
          principalAggregate {
            count
            keyMin
            keyMax
          }       
        }
        statementAggregate {
          count
          effectMin
          effectMax
        }
      }
      description
      createdAt
      maxSessionDuration
      tags {
        id
      	key
      	value
      }
      inlinePolicies
      iamAttachedPolicies {
        arn
        # Other fields and connections here...
      }
      eksCluster {
        arn
        # Other fields and connections here...
      }
      ecsService {
        arn
        # Other fields and connections here...
      }
      flowLogs {
        id
        # Other fields and connections here...
      }
      cloudFormationStack {
        arn
        # Other fields and connections here...
      }
      configurationRecorder {
        arn
        # Other fields and connections here...
      }
      codebuilds {
        arn
        # Other fields and connections here...
      }
      glueJobs {
        arn
        # Other fields and connections here...
      }
      managedAirflows {
        arn
        # Other fields and connections here...
      }
      guardDutyDetectors {
        id
        # Other fields and connections here...
      }
      sageMakerNotebookInstances {
        arn
        # Other fields and connections here...
      }
      systemsManagerInstances {
        arn
        # Other fields and connections here...
      }
      iamAttachedPolicies {
        arn
        # Other fields and connections here...
      }
    }
  }
}



References

Dgraph documentation on querying

AWS IAM User documentation

Updated 03 Mar 2023
Did this page help you?
Yes
No
PREVIOUS
IAM User
NEXT
Route 53 Overview
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Filtering
Advanced Filtering
Ordering
Aggregation
Examples
Kitchen Sink
References