I am a beginner with cdk. I have created an API Gateway and added resources and methods to it. Now I want import a swagger/YAML file into the API Gateway using CDK.
I have found this feature to be very clear over the console but I'm unable to find or understand how it is possible to do so using CDK. I have tried searching the documents but I only found importing cloud formation templates using cdk, Also there were no answers for a similar question which was asked in 2017.
CodePudding user response:
Here is a JSON import example from the CDK docs. The CloudFormation docs suggest YAML is also accepted (the CDK uploads the spec file to S3, from where CloudFormation takes over).
const api = new apigateway.SpecRestApi(this, 'books-api', {
apiDefinition: apigateway.ApiDefinition.fromAsset('path-to-file.json')
});