我正在用javascript编写一个依赖于AWS的应用程序,并且正在利用AWS CLI自动化我的AWS资源的构建过程。我正在尝试创建启用了CORS的API网关资源。在调用api网关命令行工具的put-integration-response方法时,当我添加--response-parameters参数时,收到以下错误:
>> Error parsing parameter '--response-parameters': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
>> JSON received: {method.response.header.Access-Control-Allow-Origin:'*'}下面是导致问题的--response-parameters参数:
--response-parameters {"method.response.header.Access-Control-Allow-Origin":"\'*\'"}
如果它有帮助,这个参数是通过Grunt的grunt-exec插件提供的。究竟是什么导致了这个问题?我尝试添加更多的双引号,但它们似乎没有出现在'JSON received‘中。
发布于 2020-08-03 02:21:14
以下是here针对此问题的另一个解决方案
基本上,在Windows上的JSON中使用\前面的引号: Linux/Mac:
--expression-attribute-values '{ ":u": {"S":"anotherUser"}}'在Windows上将如下所示:
--expression-attribute-values '{ \":u\": {\"S\":\"anotherUser\"}}'希望它能帮助你改正错误
发布于 2018-03-18 00:52:18
我在使用AWS Lambda Functions tutorial时也遇到了同样的问题,无论我怎么尝试,都无法获得响应模型参数来接受JSON (在Windows10上)。我最终弄明白了:我创建了一个名为response-models.json的文件,文件第一行的内容为应用程序{“/json”:"Empty"},并将其保存在当前目录中。然后,作为response-models参数的值,我使用了file://response-models.json重要信息:文件必须以不带BOM的格式保存,这样才能只输出ASCII码字符,而不会产生其他乱码。(我使用Sublime Text,它允许以UTF-8格式保存,没有BOM,以及许多其他格式。)太棒了!我得到了以下响应:
{
"statusCode": "200",
"responseModels": {
"application/json": "Empty"
}
}发布于 2017-04-26 03:50:47
可以使用“*”对静态值进行编码。
示例:
aws apigateway put-integration-response --rest-api-id xxxxx --resource-id xxxxxx --http-method GET --status-code 200 --response-parameters '{"method.response.header.Access-Control-Allow-Origin": "'"'"'*'"'"'"}' 我建议使用API SDK调用JavaScript网关来管理您的资源。您可以在SDK documentation.中找到更多信息
https://stackoverflow.com/questions/43615473
复制相似问题