Joh*_*ley 5 javascript json amazon-web-services aws-cli aws-api-gateway
我正在用 javascript 编写一个依赖 AWS 的应用程序,我正在使用 AWS CLI 来自动化我的 AWS 资源的构建过程。我正在尝试创建一个启用了 CORS 的 API 网关资源。在调用put-integration-response
api网关CLI的方法时,当我添加--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:'*'}
Run Code Online (Sandbox Code Playgroud)
这是导致问题的 --response-parameters 参数:
--response-parameters {"method.response.header.Access-Control-Allow-Origin":"\'*\'"}
如果有帮助,这个参数是通过 Grunt 的 grunt-exec 插件提供的。究竟是什么导致了这个问题?我尝试添加更多双引号,但它们似乎没有出现在“收到的 JSON”中。
小智 5
这是这里问题的另一个解决方案
基本上,您在 Windows 上的 JSON 内的引号之前使用 \:Linux/Mac:
--expression-attribute-values '{ ":u": {"S":"anotherUser"}}'
Run Code Online (Sandbox Code Playgroud)
在 Windows 上会是这样:
--expression-attribute-values '{ \":u\": {\"S\":\"anotherUser\"}}'
Run Code Online (Sandbox Code Playgroud)
希望它有助于修复您的错误
您可以通过“'”'“'*'”'“'”对静态值进行编码。
例子:
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": "'"'"'*'"'"'"}'
Run Code Online (Sandbox Code Playgroud)
我建议使用JavaScript SDK调用API Gateway来管理您的资源。您可以从 SDK 文档中找到更多信息。
归档时间: |
|
查看次数: |
8384 次 |
最近记录: |