aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.45 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});const core_1=require("../../core"),lib_1=require("../lib");class RootStack extends core_1.Stack{constructor(scope){super(scope,"integ-restapi-import-RootStack");const restApi=new lib_1.RestApi(this,"RestApi",{cloudWatchRole:!0,deploy:!1});restApi.root.addMethod("ANY");const petsStack=new PetsStack(this,{restApiId:restApi.restApiId,rootResourceId:restApi.restApiRootResourceId}),booksStack=new BooksStack(this,{restApiId:restApi.restApiId,rootResourceId:restApi.restApiRootResourceId});new DeployStack(this,{restApiId:restApi.restApiId,methods:petsStack.methods.concat(booksStack.methods)}),new core_1.CfnOutput(this,"PetsURL",{value:`https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/pets`}),new core_1.CfnOutput(this,"BooksURL",{value:`https://${restApi.restApiId}.execute-api.${this.region}.amazonaws.com/prod/books`})}}class PetsStack extends core_1.NestedStack{constructor(scope,props){super(scope,"integ-restapi-import-PetsStack",props),this.methods=[];const method=lib_1.RestApi.fromRestApiAttributes(this,"RestApi",{restApiId:props.restApiId,rootResourceId:props.rootResourceId}).root.addResource("pets").addMethod("GET",new lib_1.MockIntegration({integrationResponses:[{statusCode:"200"}],passthroughBehavior:lib_1.PassthroughBehavior.NEVER,requestTemplates:{"application/json":'{ "statusCode": 200 }'}}),{methodResponses:[{statusCode:"200"}]});this.methods.push(method)}}class BooksStack extends core_1.NestedStack{constructor(scope,props){super(scope,"integ-restapi-import-BooksStack",props),this.methods=[];const method=lib_1.RestApi.fromRestApiAttributes(this,"RestApi",{restApiId:props.restApiId,rootResourceId:props.rootResourceId}).root.addResource("books").addMethod("GET",new lib_1.MockIntegration({integrationResponses:[{statusCode:"200"}],passthroughBehavior:lib_1.PassthroughBehavior.NEVER,requestTemplates:{"application/json":'{ "statusCode": 200 }'}}),{methodResponses:[{statusCode:"200"}]});this.methods.push(method)}}class DeployStack extends core_1.NestedStack{constructor(scope,props){super(scope,"integ-restapi-import-DeployStack",props);const deployment=new lib_1.Deployment(this,"Deployment",{api:lib_1.RestApi.fromRestApiId(this,"RestApi",props.restApiId)});if(props.methods)for(const method of props.methods)deployment.node.addDependency(method);new lib_1.Stage(this,"Stage",{deployment})}}new RootStack(new core_1.App);