Initialization props for the NestedStack
construct.
import { Construct } from 'constructs';
import { App, CfnOutput, NestedStack, NestedStackProps, Stack } from '../../core';
import { Deployment, Method, MockIntegration, PassthroughBehavior, RestApi, Stage } from '../lib';
class RootStack extends Stack {
constructor(scope: Construct) {
super(scope, 'integ-restapi-import-RootStack');
const restApi = new RestApi(this, 'RestApi', {
cloudWatchRole: true,
deploy: false,
});
restApi.root.addMethod('ANY');
const petsStack = new PetsStack(this, {
restApiId: restApi.restApiId,
rootResourceId: restApi.restApiRootResourceId,
});
const booksStack = new BooksStack(this, {
restApiId: restApi.restApiId,
rootResourceId: restApi.restApiRootResourceId,
});
new DeployStack(this, {
restApiId: restApi.restApiId,
methods: petsStack.methods.concat(booksStack.methods),
});
new CfnOutput(this, 'PetsURL', {
value: `https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/pets`,
});
new CfnOutput(this, 'BooksURL', {
value: `https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/books`,
});
}
}
interface ResourceNestedStackProps extends NestedStackProps {
readonly restApiId: string;
readonly rootResourceId: string;
}
class PetsStack extends NestedStack {
public readonly methods: Method[] = [];
constructor(scope: Construct, props: ResourceNestedStackProps) {
super(scope, 'integ-restapi-import-PetsStack', props);
const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
restApiId: props.restApiId,
rootResourceId: props.rootResourceId,
});
const method = api.root.addResource('pets').addMethod('GET', new MockIntegration({
integrationResponses: [{
statusCode: '200',
}],
passthroughBehavior: PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}), {
methodResponses: [{ statusCode: '200' }],
});
this.methods.push(method);
}
}
class BooksStack extends NestedStack {
public readonly methods: Method[] = [];
constructor(scope: Construct, props: ResourceNestedStackProps) {
super(scope, 'integ-restapi-import-BooksStack', props);
const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
restApiId: props.restApiId,
rootResourceId: props.rootResourceId,
});
const method = api.root.addResource('books').addMethod('GET', new MockIntegration({
integrationResponses: [{
statusCode: '200',
}],
passthroughBehavior: PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}), {
methodResponses: [{ statusCode: '200' }],
});
this.methods.push(method);
}
}
interface DeployStackProps extends NestedStackProps {
readonly restApiId: string;
readonly methods?: Method[];
}
class DeployStack extends NestedStack {
constructor(scope: Construct, props: DeployStackProps) {
super(scope, 'integ-restapi-import-DeployStack', props);
const deployment = new Deployment(this, 'Deployment', {
api: RestApi.fromRestApiId(this, 'RestApi', props.restApiId),
});
if (props.methods) {
for (const method of props.methods) {
deployment.node.addDependency(method);
}
}
new Stage(this, 'Stage', { deployment });
}
}
new RootStack(new App());
Properties Name Type Description description? string
A description of the stack. notificationArns? string[]
The Simple Notification Service (SNS) topics to publish stack related events. parameters? { [string]: string }
The set value pairs that represent the parameters passed to CloudFormation when this nested stack is created. removalPolicy? RemovalPolicy
Policy to apply when the nested stack is removed. timeout? Duration
The length of time that CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state. description?
Type: string
(optional, default: No description.)
A description of the stack.
notificationArns?Type: string[]
(optional, default: notifications are not sent for this stack.)
The Simple Notification Service (SNS) topics to publish stack related events.
parameters?Type: { [string]: string }
(optional, default: no user-defined parameters are passed to the nested stack)
The set value pairs that represent the parameters passed to CloudFormation when this nested stack is created.
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.
removalPolicy?Type: RemovalPolicy
(optional, default: RemovalPolicy.DESTROY)
Policy to apply when the nested stack is removed.
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.
Type: Duration
(optional, default: no timeout)
The length of time that CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state.
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4