500 Internal Server Error from OPTIONS method in REST API integration with S3

0

I am unable to setup CORS on my REST API integration with S3. I am trying to configure my resource to return the list of objects in my bucket. I have enabled CORS, it created OPTIONS method but when I make OPTIONS request either from JS or curl I get 500 Internal Server Error. I've enabled detailed logs on CloudWatch and I see this:

Method request body before transformations: [Binary Data]
Execution failed due to configuration error: Unable to transform request
Method completed with status: 500

curl response

< HTTP/2 500
< date: Wed, 18 Jan 2023 21:43:27 GMT
< content-type: application/json
< content-length: 36
< x-amzn-requestid: e31e295f-2d8a-4cb5-892e-2b1b517f3650
< x-amzn-errortype: InternalServerErrorException
< x-amz-apigw-id: xxxxxxx
<
* Connection #0 to host xxxx.execute-api.eu-central-1.amazonaws.com left intact
{"message": "Internal server error"}%

Why am I getting 500 Internal Server Error from OPTIONS method? What am I missing?

This is my definition of REST API and S3 Integration in CDK (typescript)

private createS3Integration(documentsBucket: IBucket, executeRole: Role) {
    return new apigw.AwsIntegration({
      service: 's3',
      integrationHttpMethod: 'GET',
      path: '{bucket}',
      options: {
        credentialsRole: executeRole,
        integrationResponses: [
          {
            statusCode: '200',
            responseParameters: {
              'method.response.header.Content-Type': 'integration.response.header.Content-Type'
            },
          }
        ],
        requestParameters: {
          'integration.request.path.bucket': 'method.request.path.folder'
        },
      },
    });
  }

  private addDocumentsGetEndpoint(apiGateway: apigw.RestApi, s3GetIntegration: apigw.AwsIntegration) {
    apiGateway
      .root
      .addResource('{folder}')
      .addMethod('GET', s3GetIntegration, {
        methodResponses: [
          {
            statusCode: '200',
            responseParameters: {
              'method.response.header.Content-Type': true
            },
          },
        ],
        requestParameters: {
          'method.request.path.folder': true,
          'method.request.header.Content-Type': true
        },
      });
  }
1 Answer
2
Accepted Answer

Eureka! I needed to configure Content handling: Convert to text (if needed). This solved my issue.

jedrek
answered a year ago
  • Where did you make that (please share console screenshot)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions