通过 CLI 更新 AWS API Gateway 资源策略的语法是否正确?

2024-03-18

我正在尝试通过 CLI 更新 API 网关实例上的资源策略,但我似乎找不到正确的 JSON 语法。在文档中,它说使用“​​补丁操作”,据我了解,它需要一串 JSON 来表示策略。我尝试过缩小 JSON、转义 JSON、单引号、无引号,但似乎都不起作用。该文档在补丁操作的值字段中没有实际 JSON 的示例,所以我感觉有点迷失。

我一直在尝试这个命令的变体:

aws apigateway update-rest-api --rest-api-id abcde123 --patch-operations op=replace,path=/policy,value='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"execute-api:Invoke","Resource":"arn:aws:execute-api:region:000000000000:*"},{"Effect":"Deny","Principal":"*","Action":"execute-api:Invoke","Resource":"arn:aws:execute-api:region:000000000000:*","Condition":{"StringNotEquals":{"aws:SourceVpce":["vpce-123456789","vpce-987654321"]}}}]}'

我每次都会收到错误消息:

Error parsing parameter '--patch-operations': Expected: '=', received: '{' for input:

相关文档here https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-resource.html.


以下命令已针对我的环境进行了测试 - (使用 bash)

aws apigateway update-rest-api --rest-api-id %REST_API_ID% --patch-operations op=replace,path=/policy,value='"{\"Version
\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"execute-api:Invoke\",\"Resource
\":\"arn:aws:execute-api:region:000000000000:*\"},{\"Effect\":\"Deny\",\"Principal\":\"*\",\"Action\":\"execute-api:Inv
oke\",\"Resource\":\"arn:aws:execute-api:region:000000000000:*\",\"Condition\":{\"StringNotEquals\":{\"aws:SourceVpce\"
:[\"vpce-123456789\",\"vpce-987654321\"]}}}]}"' --region %REGION%

关键是将JSON对象转换为文本字符串化,我已经使用这个网站 https://onlinetexttools.com/json-stringify-text。基本上,将 JSON 粘贴到输入文本框中,然后将字符串化文本复制到 AWS CLI 命令中。

更多信息here https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies-create-attach.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 CLI 更新 AWS API Gateway 资源策略的语法是否正确? 的相关文章

随机推荐