App

class aws_cdk.App(*, analytics_reporting=None, auto_synth=None, context=None, default_stack_synthesizer=None, outdir=None, policy_validation_beta1=None, post_cli_context=None, stack_traces=None, tree_metadata=None)

Bases: Stage

A construct which represents an entire CDK app. This construct is normally the root of the construct tree.

You would normally define an App instance in your program’s entrypoint, then define constructs where the app is used as the parent scope.

After all the child constructs are defined within the app, you should call app.synth() which will emit a “cloud assembly” from this app into the directory specified by outdir. Cloud assemblies includes artifacts such as CloudFormation templates and assets that are needed to deploy this app into the AWS cloud.

See:

https://docs.aws.amazon.com/cdk/latest/guide/apps.html

ExampleMetadata:

infused

Example:

import aws_cdk as cdk
import aws_cdk.aws_s3 as s3

# bucket: s3.IBucket


app = cdk.App()
stack = cdk.Stack(app, "Stack")

dynamodb.Table(stack, "Table",
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING
    ),
    import_source=dynamodb.ImportSourceSpecification(
        compression_type=dynamodb.InputCompressionType.GZIP,
        input_format=dynamodb.InputFormat.csv(
            delimiter=",",
            header_list=["id", "name"]
        ),
        bucket=bucket,
        key_prefix="prefix"
    )
)

Initializes a CDK application.

Parameters:
  • analytics_reporting (Optional[bool]) – Include runtime versioning information in the Stacks of this app. Default: Value of ‘aws:cdk:version-reporting’ context key

  • auto_synth (Optional[bool]) – Automatically call synth() before the program exits. If you set this, you don’t have to call synth() explicitly. Note that this feature is only available for certain programming languages, and calling synth() is still recommended. Default: true if running via CDK CLI (CDK_OUTDIR is set), false otherwise

  • context (Optional[Mapping[str, Any]]) – Additional context values for the application. Context set by the CLI or the context key in cdk.json has precedence. Context can be read from any construct using node.getContext(key). Default: - no additional context

  • default_stack_synthesizer (Optional[IReusableStackSynthesizer]) – The stack synthesizer to use by default for all Stacks in the App. The Stack Synthesizer controls aspects of synthesis and deployment, like how assets are referenced and what IAM roles to use. For more information, see the README of the main CDK package. Default: - A DefaultStackSynthesizer with default settings

  • outdir (Optional[str]) – The output directory into which to emit synthesized artifacts. You should never need to set this value. By default, the value you pass to the CLI’s --output flag will be used, and if you change it to a different directory the CLI will fail to pick up the generated Cloud Assembly. This property is intended for internal and testing use. Default: - If this value is not set, considers the environment variable CDK_OUTDIR. If CDK_OUTDIR is not defined, uses a temp directory.

  • policy_validation_beta1 (Optional[Sequence[IPolicyValidationPluginBeta1]]) – Validation plugins to run after synthesis. Default: - no validation plugins

  • post_cli_context (Optional[Mapping[str, Any]]) – Additional context values for the application. Context provided here has precedence over context set by: - The CLI via –context - The context key in cdk.json - The AppProps.context property This property is recommended over the AppProps.context property since you can make final decision over which context value to take in your app. Context can be read from any construct using node.getContext(key). Default: - no additional context

  • stack_traces (Optional[bool]) – Include construct creation stack trace in the aws:cdk:trace metadata key of all constructs. Default: true stack traces are included unless aws:cdk:disable-stack-trace is set in the context.

  • tree_metadata (Optional[bool]) – Include construct tree metadata as part of the Cloud Assembly. Default: true

Methods

synth(*, error_on_duplicate_synth=None, force=None, skip_validation=None, validate_on_synthesis=None)

Synthesize this stage into a cloud assembly.

Once an assembly has been synthesized, it cannot be modified. Subsequent calls will return the same assembly.

Parameters:
  • error_on_duplicate_synth (Optional[bool]) – Whether or not to throw a warning instead of an error if the construct tree has been mutated since the last synth. Default: true

  • force (Optional[bool]) – Force a re-synth, even if the stage has already been synthesized. This is used by tests to allow for incremental verification of the output. Do not use in production. Default: false

  • skip_validation (Optional[bool]) – Should we skip construct validation. Default: - false

  • validate_on_synthesis (Optional[bool]) – Whether the stack should be validated after synthesis to check for error metadata. Default: - false

Return type:

CloudAssembly

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

account

The default account for all resources defined within this stage.

artifact_id

Artifact ID of the assembly if it is a nested stage. The root stage (app) will return an empty string.

Derived from the construct path.

asset_outdir

The cloud assembly asset output directory.

node

The tree node.

outdir

The cloud assembly output directory.

parent_stage

The parent stage or undefined if this is the app.

policy_validation_beta1

Validation plugins to run during synthesis.

If any plugin reports any violation, synthesis will be interrupted and the report displayed to the user.

Default:
  • no validation plugins are used

region

The default region for all resources defined within this stage.

stage_name

The name of the stage.

Based on names of the parent stages separated by hypens.

Static Methods

classmethod is_app(obj)

Checks if an object is an instance of the App class.

Parameters:

obj (Any) – The object to evaluate.

Return type:

bool

Returns:

true if obj is an App.

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_stage(x)

Test whether the given construct is a stage.

Parameters:

x (Any) –

Return type:

bool

classmethod of(construct)

Return the stage this construct is contained with, if available.

If called on a nested stage, returns its parent.

Parameters:

construct (IConstruct) –

Return type:

Optional[Stage]