REST API 与 S3 集成中的 OPTIONS 方法出现 500 内部服务器错误

0

【以下的问题经过翻译处理】 我无法在 REST API 与 S3 集成上设置 CORS。 我正在尝试配置我的资源以返回我的存储桶中的对象列表。 我启用了 CORS,它创建了 OPTIONS 方法,但是当我从 JS 或curl 发出 OPTIONS 请求时,我收到 500 内部服务器错误。 我已在 CloudWatch 上启用详细日志,并且看到以下内容: ''' Method request body before transformations: [Binary Data] Execution failed due to configuration error: Unable to transform request Method completed with status: 500 ''' curl响应: ''' < 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"}% ''' 为什么我从 OPTIONS 方法中收到 500 内部服务器错误? 我缺少什么? 这是我在 CDK 中对 REST API 和 S3 集成的定义(打字稿) ''' 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 Antwort
0

【以下的回答经过翻译处理】 尤里卡! 我需要配置内容处理:转换为文本(如果需要)。 这解决了我的问题。

profile picture
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen