Show / Hide Table of Contents

Class NestedStackProps

Initialization props for the NestedStack construct.

Inheritance
object
NestedStackProps
Implements
INestedStackProps
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class NestedStackProps : INestedStackProps
Syntax (vb)
Public Class NestedStackProps Implements INestedStackProps
Remarks

ExampleMetadata: lit=aws-apigateway/test/integ.restapi-import.lit.ts infused

Examples
using Constructs;
            using Amazon.CDK;
            using Amazon.CDK.AWS.APIGateway;

            /**
             * This file showcases how to split up a RestApi's Resources and Methods across nested stacks.
             *
             * The root stack 'RootStack' first defines a RestApi.
             * Two nested stacks BooksStack and PetsStack, create corresponding Resources '/books' and '/pets'.
             * They are then deployed to a 'prod' Stage via a third nested stack - DeployStack.
             *
             * To verify this worked, go to the APIGateway
             */

            class RootStack : Stack
            {
                public RootStack(Construct scope) : base(scope, "integ-restapi-import-RootStack")
                {

                    var restApi = new RestApi(this, "RestApi", new RestApiProps {
                        CloudWatchRole = true,
                        Deploy = false
                    });
                    restApi.Root.AddMethod("ANY");

                    var petsStack = new PetsStack(this, new ResourceNestedStackProps {
                        RestApiId = restApi.RestApiId,
                        RootResourceId = restApi.RestApiRootResourceId
                    });
                    var booksStack = new BooksStack(this, new ResourceNestedStackProps {
                        RestApiId = restApi.RestApiId,
                        RootResourceId = restApi.RestApiRootResourceId
                    });
                    new DeployStack(this, new DeployStackProps {
                        RestApiId = restApi.RestApiId,
                        Methods = petsStack.Methods.Concat(booksStack.Methods)
                    });

                    new CfnOutput(this, "PetsURL", new CfnOutputProps {
                        Value = $"https://{restApi.restApiId}.execute-api.{this.region}.amazonaws.com/prod/pets"
                    });

                    new CfnOutput(this, "BooksURL", new CfnOutputProps {
                        Value = $"https://{restApi.restApiId}.execute-api.{this.region}.amazonaws.com/prod/books"
                    });
                }
            }

            class ResourceNestedStackProps : NestedStackProps
            {
                public string RestApiId { get; set; }

                public string RootResourceId { get; set; }
            }

            class PetsStack : NestedStack
            {
                public readonly Method[] Methods = new [] {  };

                public PetsStack(Construct scope, ResourceNestedStackProps props) : base(scope, "integ-restapi-import-PetsStack", props)
                {

                    var api = RestApi.FromRestApiAttributes(this, "RestApi", new RestApiAttributes {
                        RestApiId = props.RestApiId,
                        RootResourceId = props.RootResourceId
                    });

                    var method = api.Root.AddResource("pets").AddMethod("GET", new MockIntegration(new IntegrationOptions {
                        IntegrationResponses = new [] { new IntegrationResponse {
                            StatusCode = "200"
                        } },
                        PassthroughBehavior = PassthroughBehavior.NEVER,
                        RequestTemplates = new Dictionary<string, string> {
                            { "application/json", "{ \"statusCode\": 200 }" }
                        }
                    }), new MethodOptions {
                        MethodResponses = new [] { new MethodResponse { StatusCode = "200" } }
                    });

                    Methods.Push(method);
                }
            }

            class BooksStack : NestedStack
            {
                public readonly Method[] Methods = new [] {  };

                public BooksStack(Construct scope, ResourceNestedStackProps props) : base(scope, "integ-restapi-import-BooksStack", props)
                {

                    var api = RestApi.FromRestApiAttributes(this, "RestApi", new RestApiAttributes {
                        RestApiId = props.RestApiId,
                        RootResourceId = props.RootResourceId
                    });

                    var method = api.Root.AddResource("books").AddMethod("GET", new MockIntegration(new IntegrationOptions {
                        IntegrationResponses = new [] { new IntegrationResponse {
                            StatusCode = "200"
                        } },
                        PassthroughBehavior = PassthroughBehavior.NEVER,
                        RequestTemplates = new Dictionary<string, string> {
                            { "application/json", "{ \"statusCode\": 200 }" }
                        }
                    }), new MethodOptions {
                        MethodResponses = new [] { new MethodResponse { StatusCode = "200" } }
                    });

                    Methods.Push(method);
                }
            }

            class DeployStackProps : NestedStackProps
            {
                public string RestApiId { get; set; }

                public Method[]? Methods { get; set; }
            }

            class DeployStack : NestedStack
            {
                public DeployStack(Construct scope, DeployStackProps props) : base(scope, "integ-restapi-import-DeployStack", props)
                {

                    var deployment = new Deployment(this, "Deployment", new DeploymentProps {
                        Api = RestApi.FromRestApiId(this, "RestApi", props.RestApiId)
                    });
                    if (props.Methods)
                    {
                        for (var method in props.Methods)
                        {
                            deployment.Node.AddDependency(method);
                        }
                    }
                    new Stage(this, "Stage", new StageProps { Deployment = deployment });
                }
            }

            new RootStack(new App());

Synopsis

Constructors

NestedStackProps()

Initialization props for the NestedStack construct.

Properties

Description

A description of the stack.

NotificationArns

The Simple Notification Service (SNS) topics to publish stack related events.

Parameters

The set value pairs that represent the parameters passed to CloudFormation when this nested stack is created.

RemovalPolicy

Policy to apply when the nested stack is removed.

SuppressTemplateIndentation

Enable this flag to suppress indentation in generated CloudFormation templates.

Timeout

The length of time that CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state.

Constructors

NestedStackProps()

Initialization props for the NestedStack construct.

public NestedStackProps()
Remarks

ExampleMetadata: lit=aws-apigateway/test/integ.restapi-import.lit.ts infused

Examples
using Constructs;
            using Amazon.CDK;
            using Amazon.CDK.AWS.APIGateway;

            /**
             * This file showcases how to split up a RestApi's Resources and Methods across nested stacks.
             *
             * The root stack 'RootStack' first defines a RestApi.
             * Two nested stacks BooksStack and PetsStack, create corresponding Resources '/books' and '/pets'.
             * They are then deployed to a 'prod' Stage via a third nested stack - DeployStack.
             *
             * To verify this worked, go to the APIGateway
             */

            class RootStack : Stack
            {
                public RootStack(Construct scope) : base(scope, "integ-restapi-import-RootStack")
                {

                    var restApi = new RestApi(this, "RestApi", new RestApiProps {
                        CloudWatchRole = true,
                        Deploy = false
                    });
                    restApi.Root.AddMethod("ANY");

                    var petsStack = new PetsStack(this, new ResourceNestedStackProps {
                        RestApiId = restApi.RestApiId,
                        RootResourceId = restApi.RestApiRootResourceId
                    });
                    var booksStack = new BooksStack(this, new ResourceNestedStackProps {
                        RestApiId = restApi.RestApiId,
                        RootResourceId = restApi.RestApiRootResourceId
                    });
                    new DeployStack(this, new DeployStackProps {
                        RestApiId = restApi.RestApiId,
                        Methods = petsStack.Methods.Concat(booksStack.Methods)
                    });

                    new CfnOutput(this, "PetsURL", new CfnOutputProps {
                        Value = $"https://{restApi.restApiId}.execute-api.{this.region}.amazonaws.com/prod/pets"
                    });

                    new CfnOutput(this, "BooksURL", new CfnOutputProps {
                        Value = $"https://{restApi.restApiId}.execute-api.{this.region}.amazonaws.com/prod/books"
                    });
                }
            }

            class ResourceNestedStackProps : NestedStackProps
            {
                public string RestApiId { get; set; }

                public string RootResourceId { get; set; }
            }

            class PetsStack : NestedStack
            {
                public readonly Method[] Methods = new [] {  };

                public PetsStack(Construct scope, ResourceNestedStackProps props) : base(scope, "integ-restapi-import-PetsStack", props)
                {

                    var api = RestApi.FromRestApiAttributes(this, "RestApi", new RestApiAttributes {
                        RestApiId = props.RestApiId,
                        RootResourceId = props.RootResourceId
                    });

                    var method = api.Root.AddResource("pets").AddMethod("GET", new MockIntegration(new IntegrationOptions {
                        IntegrationResponses = new [] { new IntegrationResponse {
                            StatusCode = "200"
                        } },
                        PassthroughBehavior = PassthroughBehavior.NEVER,
                        RequestTemplates = new Dictionary<string, string> {
                            { "application/json", "{ \"statusCode\": 200 }" }
                        }
                    }), new MethodOptions {
                        MethodResponses = new [] { new MethodResponse { StatusCode = "200" } }
                    });

                    Methods.Push(method);
                }
            }

            class BooksStack : NestedStack
            {
                public readonly Method[] Methods = new [] {  };

                public BooksStack(Construct scope, ResourceNestedStackProps props) : base(scope, "integ-restapi-import-BooksStack", props)
                {

                    var api = RestApi.FromRestApiAttributes(this, "RestApi", new RestApiAttributes {
                        RestApiId = props.RestApiId,
                        RootResourceId = props.RootResourceId
                    });

                    var method = api.Root.AddResource("books").AddMethod("GET", new MockIntegration(new IntegrationOptions {
                        IntegrationResponses = new [] { new IntegrationResponse {
                            StatusCode = "200"
                        } },
                        PassthroughBehavior = PassthroughBehavior.NEVER,
                        RequestTemplates = new Dictionary<string, string> {
                            { "application/json", "{ \"statusCode\": 200 }" }
                        }
                    }), new MethodOptions {
                        MethodResponses = new [] { new MethodResponse { StatusCode = "200" } }
                    });

                    Methods.Push(method);
                }
            }

            class DeployStackProps : NestedStackProps
            {
                public string RestApiId { get; set; }

                public Method[]? Methods { get; set; }
            }

            class DeployStack : NestedStack
            {
                public DeployStack(Construct scope, DeployStackProps props) : base(scope, "integ-restapi-import-DeployStack", props)
                {

                    var deployment = new Deployment(this, "Deployment", new DeploymentProps {
                        Api = RestApi.FromRestApiId(this, "RestApi", props.RestApiId)
                    });
                    if (props.Methods)
                    {
                        for (var method in props.Methods)
                        {
                            deployment.Node.AddDependency(method);
                        }
                    }
                    new Stage(this, "Stage", new StageProps { Deployment = deployment });
                }
            }

            new RootStack(new App());

Properties

Description

A description of the stack.

public string? Description { get; set; }
Property Value

string

Remarks

Default: - No description.

NotificationArns

The Simple Notification Service (SNS) topics to publish stack related events.

public string[]? NotificationArns { get; set; }
Property Value

string[]

Remarks

Default: - notifications are not sent for this stack.

Parameters

The set value pairs that represent the parameters passed to CloudFormation when this nested stack is created.

public IDictionary<string, string>? Parameters { get; set; }
Property Value

IDictionary<string, string>

Remarks

Each parameter has a name corresponding to a parameter defined in the embedded template and a value representing the value that you want to set for the parameter.

The nested stack construct will automatically synthesize parameters in order to bind references from the parent stack(s) into the nested stack.

Default: - no user-defined parameters are passed to the nested stack

RemovalPolicy

Policy to apply when the nested stack is removed.

public RemovalPolicy? RemovalPolicy { get; set; }
Property Value

RemovalPolicy?

Remarks

The default is Destroy, because all Removal Policies of resources inside the Nested Stack should already have been set correctly. You normally should not need to set this value.

Default: RemovalPolicy.DESTROY

SuppressTemplateIndentation

Enable this flag to suppress indentation in generated CloudFormation templates.

public bool? SuppressTemplateIndentation { get; set; }
Property Value

bool?

Remarks

If not specified, the value of the @aws-cdk/core:suppressTemplateIndentation context key will be used. If that is not specified, then the default value false will be used.

Default: - the value of @aws-cdk/core:suppressTemplateIndentation, or false if that is not set.

Timeout

The length of time that CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state.

public Duration? Timeout { get; set; }
Property Value

Duration

Remarks

When CloudFormation detects that the nested stack has reached the CREATE_COMPLETE state, it marks the nested stack resource as CREATE_COMPLETE in the parent stack and resumes creating the parent stack. If the timeout period expires before the nested stack reaches CREATE_COMPLETE, CloudFormation marks the nested stack as failed and rolls back both the nested stack and parent stack.

Default: - no timeout

Implements

INestedStackProps
Back to top Generated by DocFX