ERROR 验证错误:Lambda 函数结果验证失败,该函数尝试删除只读标头, headerName : Content-Length

Yah*_*iya 4 amazon-cloudfront aws-lambda-edge

每当我尝试添加响应标头时,CloudFront 都会向我抛出

ERROR 验证错误:Lambda 函数结果验证失败,该函数尝试删除只读标头 headerName : Content-Length。

ERROR 验证错误:Lambda 函数结果验证失败,该函数尝试删除只读标头 headerName :Content-Encoding。

const response = {
      status: '302',
      statusDescription: 'Found',
      headers: {
                'location': [{
                              key: 'location',
                              value: 'https://abc.test.io'
                             }],
                 'set-cookie': [{
                               key: 'set-cookie',
                               value: 'sessiontoken='+sessionObjectData.session.sessionId+'; Secure; HttpOnly'
                                }]
                }
  }
callback(null, response)
Run Code Online (Sandbox Code Playgroud)

有人可以让我知道我在这里做错了什么吗?顺便说一句,我正在使用观众响应事件

小智 5

正如CloudFront 函数文档中所述,无法修改 Edge Functions 的某些响应标头(包括“Content-Length”)。您可以尝试的是仅更新您需要更改的标头,而其他标头保持不变:

const response = event.Records[0].cf.response;
response.status = 302;
response.statusDescription = 'Found';
response.headers['location'] = [{ key: 'Location', value:'https://abc.test.io'}];
Run Code Online (Sandbox Code Playgroud)