Skip to content

cdk.star

Set AWS CDK context values, such as feature flags, in cdk.json.

Edits keep cdk.json's key order and indentation. The aws-cdk-lib version itself lives in package.json, pyproject.toml, pom.xml or go.mod; use npm.set_dependency, python.set_requirement, maven.set_dependency or a go get step for it.

load("@fleet//cdk.star", "apps", "set_context")
Function What it does
apps Lists the repo's CDK apps.
set_context Sets a context value, such as a feature flag, in every cdk.json.

apps

apps(repo)

Lists the repo's CDK apps.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The sorted paths of every cdk.json outside node_modules and cdk.out.

Example

apps(repo)
# returns ["cdk.json", "infra/cdk.json"]

cdk.json

{"app": "npx ts-node bin/app.ts"}

infra/cdk.json

{"app": "python3 app.py"}

Source

set_context

set_context(repo, key, value, only_existing = False)

Sets a context value, such as a feature flag, in every cdk.json.

Arguments

Name Description
repo The repo passed to change(repo).
key The context key, such as @aws-cdk/aws-lambda:recognizeLayerVersion.
value Any JSON value.
only_existing When True, only apps that already set the key change.

Returns: The list of paths that changed.

Example

set_context(repo, "@aws-cdk/aws-s3:createDefaultLoggingPolicy", True)
# returns ["cdk.json"]

cdk.json

{
  "app": "npx ts-node bin/app.ts",
  "context": {
    "@aws-cdk/core:stackRelativeExports": true
  }
}

cdk.json

{
  "app": "npx ts-node bin/app.ts",
  "context": {
    "@aws-cdk/core:stackRelativeExports": true,
    "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true
  }
}

Used in: cdk-feature-flags

Source