# CcApiContextQuery

Query input for lookup up CloudFormation resources using CC API.

The example below is required to successfully compile CDK (otherwise,
the CDK build will generate a synthetic example for the below, but it
doesn't have enough type information about the literal string union
to generate a validly compiling example).

Extends: [ContextLookupRoleOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.cloud_assembly_schema.ContextLookupRoleOptions.html)

- Source: [`lib/cloud-assembly/context-queries.ts`](https://github.com/aws/aws-cdk-cli/blob/HEAD/packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts)
- Type last changed: v2.239.0 · 19 Feb 2026

## Example

TypeScript:

```ts
import { CcApiContextQuery } from '@aws-cdk/cloud-assembly-schema';

const x: CcApiContextQuery = {
  typeName: 'AWS::Some::Type',
  expectedMatchCount: 'exactly-one',
  resourceModel: {SomeArn: 'arn:aws:....'},
  propertiesToReturn: ['SomeProp'],
  account: '11111111111',
  region: 'us-east-1',
};
```

Python:

```python
from aws_cdk.cloud_assembly_schema import CcApiContextQuery
from aws_cdk.cloud_assembly_schema import CcApiContextQuery

x = CcApiContextQuery(
    type_name="AWS::Some::Type",
    expected_match_count="exactly-one",
    resource_model={"SomeArn": "arn:aws:...."},
    properties_to_return=["SomeProp"],
    account="11111111111",
    region="us-east-1"
)
```

Java:

```java
import software.amazon.awscdk.cloudassembly.schema.CcApiContextQuery;

CcApiContextQuery x = CcApiContextQuery.builder()
        .typeName("AWS::Some::Type")
        .expectedMatchCount("exactly-one")
        .resourceModel(Map.of("SomeArn", "arn:aws:...."))
        .propertiesToReturn(List.of("SomeProp"))
        .account("11111111111")
        .region("us-east-1")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.CloudAssembly.Schema;

var x = new CcApiContextQuery {
    TypeName = "AWS::Some::Type",
    ExpectedMatchCount = "exactly-one",
    ResourceModel = new Dictionary<string, object> { { "SomeArn", "arn:aws:...." } },
    PropertiesToReturn = new [] { "SomeProp" },
    Account = "11111111111",
    Region = "us-east-1"
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/cdklabs/cloud-assembly-schema-go/awscdkcloudassemblyschema"

x := &CcApiContextQuery{
	TypeName: jsii.String("AWS::Some::Type"),
	ExpectedMatchCount: jsii.String("exactly-one"),
	ResourceModel: map[string]interface{}{
		"SomeArn": jsii.String("arn:aws:...."),
	},
	PropertiesToReturn: []*string{
		jsii.String("SomeProp"),
	},
	Account: jsii.String("11111111111"),
	Region: jsii.String("us-east-1"),
}
```

## Properties

- `account`: string (required) — Query account.

- `assumeRoleAdditionalOptions`: { [key: string]: any } — Additional options to pass to STS when assuming the lookup role.

  **Default:** No additional options.

  - `RoleArn` should not be used. Use the dedicated `lookupRoleArn` property instead.
  - `ExternalId` should not be used. Use the dedicated `lookupRoleExternalId` instead.

- `dummyValue`: any — The value to return if the resource was not found and `ignoreErrorOnMissingContext` is true.

  **Default:** No dummy value available

  If supplied, `dummyValue` should be an array of objects.

  `dummyValue` does not have to have elements, and it may have objects with
  different properties than the properties in `propertiesToReturn`, but it
  will be easiest for downstream code if the `dummyValue` conforms to
  the expected response shape.

- `exactIdentifier`: string — Identifier of the resource to look up using `GetResource`.

  **Default:** Either exactIdentifier or propertyMatch should be specified.

  Specifying exactIdentifier will return exactly one result, or throw an error
  unless `ignoreErrorOnMissingContext` is set.

- `expectedMatchCount`: string = 'any' — Expected count of results if `propertyMatch` is specified.

  If the expected result count does not match the actual count,
  by default an error is produced and the result is not committed to cached
  context, and the user can correct the situation and try again without
  having to manually clear out the context key using `cdk context --remove`

  If the value of * `ignoreErrorOnMissingContext` is `true`, the value of
  `expectedMatchCount` is `at-least-one | exactly-one` and the number
  of found resources is 0, `dummyValue` is returned and committed to context
  instead.

- `ignoreErrorOnMissingContext`: boolean = false — Ignore an error and return the `dummyValue` instead if the resource was not found.

  - In case of an `exactIdentifier` lookup, return the `dummyValue` if the resource with
    that identifier was not found.
  - In case of a `propertyMatch` lookup, return the `dummyValue` if `expectedMatchCount`
    is `at-least-one | exactly-one` and the number of resources found was 0.

  if `ignoreErrorOnMissingContext` is set, `dummyValue` should be set and be an array.

- `lookupRoleArn`: string = None — The ARN of the role that should be used to look up the missing values.

- `lookupRoleExternalId`: string — The ExternalId that needs to be supplied while assuming this role.

  **Default:** No ExternalId will be supplied

- `propertiesToReturn`: string[] (required) — This is a set of properties returned from CC API that we want to return from ContextQuery.

  If any properties listed here are absent from the target resource, an error will be thrown.

  The returned object will always include the key `Identifier` with the CC-API returned
  field `Identifier`.

  ## Notes on property completeness

  CloudControl API's `ListResources` may return fewer properties than
  `GetResource` would, depending on the resource implementation.

  The returned properties here are *currently* selected from the response
  object that CloudControl API returns to the CDK CLI.

  However, if we find there is need to do so, we may decide to change this
  behavior in the future: we might change it to perform an additional
  `GetResource` call for resources matched by `propertyMatch`.

- `propertyMatch`: { [key: string]: any } — Returns any resources matching these properties, using `ListResources`.

  **Default:** Either exactIdentifier or propertyMatch should be specified.

  By default, specifying propertyMatch will successfully return 0 or more
  results. To throw an error if the number of results is unexpected (and
  prevent the query results from being committed to context), specify
  `expectedMatchCount`.

  ## Notes on property completeness

  CloudControl API's `ListResources` may return fewer properties than
  `GetResource` would, depending on the resource implementation.

  The resources that `propertyMatch` matches against will *only ever* be the
  properties returned by the `ListResources` call.

- `region`: string (required) — Query region.

- `resourceModel`: { [key: string]: any } — The resource model to use to select the resources, using `ListResources`..

  **Default:** no resource Model is provided

  This is needed for sub-resources where the parent Arn is required.

  See https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/resource-operations-list.html#resource-operations-list-containers

- `typeName`: string (required) — The CloudFormation resource type.

  See https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/supported-resources.html
