Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

408
Views
aws cdk: serve swagger ui with api gateway

I want to use AWS ApiGateway to serve a swagger-ui of an API from a lambda function using express. For this I want to use the endpoint GET /docs. My Lambda function swaggerUiLambdaHandler looks like this:

import express from 'express';
import serverless from 'serverless-http';
import swaggerUI from 'swagger-ui-express';

const options = {
  swaggerOptions: {
    url: 'https://petstore.swagger.io/v2/swagger.json',
  },
};

const app = express();
app.use('/v1/docs', swaggerUI.serve, swaggerUI.setup(undefined, options));

module.exports.handler = serverless(app);

In the cdk stack of the api, I added the following 2 endpoints for serving the index.html and the .js/.css resources:

const docs = myApi.root.addResource('docs');
docs.addMethod('GET', new apigw.LambdaIntegration(swaggerUiLambdaHandler));
const docsProxy = docs.addResource('{proxy+}');
docsProxy.addMethod('GET', new apigw.LambdaIntegration(swaggerUiLambdaHandler));

However, calling the endpoint with the browser, all network requests succeed but I get a white canvas and the error

Uncaught SyntaxError: Unexpected token '<'

Do you have any idea? I think it might be related to the content-type returned by api gateway, but I would appreciate some help.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!