I am creating proxy API gateway to non-public S3 bucket using CDK. The S3 bucket contains html, javascript, and css files.
I created an api using CDK like this:
const api = new apigw.RestApi(this, 'Test-Web')
api.root
.addResource('{file}')
.addMethod('GET', new apigw.AwsIntegration({
service: 's3',
integrationHttpMethod: 'GET',
path: `${bucket.bucketName}/{file}`,
options: {
credentialsRole: role,
requestParameters: {
'integration.request.path.file': 'method.request.path.file'
},
integrationResponses: [{
statusCode: '200'
}]
}
}), {
requestParameters: {
'method.request.path.file': true
},
methodResponses: [{
statusCode: '200'
}]
})
It works fine, but has a problem. The content type of the response is always set to application/json. I could see that the content type of integration responses (responses from S3) varies from text/html to text/css, application/javascript depending on the file.
How can I set this API to return correct content type on each file by passing the same content type header value of integration response to method response? Best if I can pass the content-type header from S3 as it already returns correctly.