[英]Getting error when using local amplify mock api: The request has a 'X-Amzn-Trace-Id' HTTP header which is reserved for AWS X-Ray trace header
I am currently using Amplify to set up my backend because Appsync is a key part of my stack.我目前正在使用 Amplify 来设置我的后端,因为 Appsync 是我堆栈的关键部分。
However, I also use SQS to publish certain messages into a queue.但是,我还使用 SQS 将某些消息发布到队列中。 This is easily done using the in-code editor of lambda but since I'm running lambda functions locally now, I am unable to send messages to the queue now with the following error:
使用 lambda 的代码内编辑器可以轻松完成此操作,但由于我现在在本地运行 lambda 函数,因此我现在无法将消息发送到队列,并出现以下错误:
InvalidParameterValue: The request has a 'X-Amzn-Trace-Id' HTTP header which is reserved for AWS X-Ray trace header and has an invalid value 'amplify-mock-x-amzn-trace-id' InvalidParameterValue:请求具有“X-Amzn-Trace-Id”HTTP header,这是为 AWS X-Ray 跟踪 header 保留的,并且具有无效值“amplify-mock-x-amzn-trace-id”
This is my code to send messages into the queue.这是我将消息发送到队列中的代码。
response = await sqs.sendMessageBatch(slackParams).promise().catch(async (err) => { console.log( response from sqs: ${err}
); }); response = await sqs.sendMessageBatch(slackParams).promise().catch(async (err) => { console.log(
response from sqs: ${err}
); });
Once I do amplify push, the code works fine on the cloud lambda but the issue comes only when I do amplify mock api. (During local testing, I am unable to add to the queue)一旦我放大推送,代码在云 lambda 上运行良好,但只有当我放大模拟 api 时才会出现问题。(在本地测试期间,我无法添加到队列中)
Is there any way I can mock my SQS setup locally as well?有什么方法可以在本地模拟我的 SQS 设置吗? Any help is appreciated!
任何帮助表示赞赏!
I've just started receiving the same error, but when sending a message to sns.我刚开始收到同样的错误,但是在向 sns 发送消息时。 It has been working for quite sometime, but the issue started showing up yesterday.
它已经工作了很长一段时间,但问题是昨天开始出现的。
When you run locally, you can add a valid trace id to the headers through the environment variables with something like process.env._X_AMZN_TRACE_ID = 'Root=1-63b6ffe7-2c48b4e36086hhhf21d16c8c;Parent=51740oo32a9d2e68;Sampled=0'
and it should stop bothering you.当您在本地运行时,您可以通过环境变量向标头添加有效的跟踪 ID,例如
process.env._X_AMZN_TRACE_ID = 'Root=1-63b6ffe7-2c48b4e36086hhhf21d16c8c;Parent=51740oo32a9d2e68;Sampled=0'
它应该停止打扰你。 Definitely a bug on Amazon's part that they would autopopulate this header with an invalid value, but it seems like if you pass in any valid X-Amzn-Trace-Id
it will work.绝对是亚马逊方面的一个错误,他们会使用无效值自动填充此 header,但似乎如果您传入任何有效
X-Amzn-Trace-Id
它将起作用。 I added a line to my function to print the trace Id, ran it on the cloud, and checked the logs to get a valid id.我在我的 function 中添加了一行来打印跟踪 ID,在云端运行它,并检查日志以获取有效 ID。 Maybe the suggested code above will work for you, but you might have to run on the cloud to get an id yourself.
也许上面建议的代码对你有用,但你可能必须在云上运行才能自己获得一个 id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.