I would like to build an AWS API, using AWS CDK, AWS SAM en OpenAPI. As far I know, you can use new sam.CfnApi to link an OpenAPI spec to AWS SAM. But unfortunately, I got stuck in doing this.
I build my project with cdk synth, sam build and sam deploy. When I do sam deploy, I got a CREATE_FAILED with the reason:
Resource handler returned message: "Invalid OpenAPI input. (Service: ApiGateway, Status Code: 400, Request ID: 295a6724-4f91-43c5-b466-18260a1e0fab)" (RequestToken: 92104c4c-8ef5-7118-8abb-2cbdb51f5893, HandlerErrorCode: InvalidRequest)
I use the following code to build an API..
The code I have, is this:
export class PortalXStack extends Stack {
constructor(scope: Construct, id: string, props: PortalXStackProps) {
super(scope, id, props);
const data = fs.readFileSync('openapi-spec.yml');
const restApi = new sam.CfnApi(this, 'ApiGateway2', {
stageName: props.stageName,
definitionBody: data
});
}
}
The openapi-spec.yml I have:
openapi: 3.0.3
info:
title: Portal X
description: Portal X
version: 0.0.1
servers:
- url: https://portal-x/v1
paths:
/:
get:
summary: Get something
responses:
200:
description: Something was ok