如何使用AWS cli用json文件替换现有的策略?



我正在尝试使用AWS cli更新我的一个API网关中的策略,这是出于自动化目的。当我尝试使用policy json with command时,它成功了,但当我尝试使用指向json文件执行它时,它会给出错误,

aws apigateway update-rest-api --rest-api-id cyasdze47d --patch-operations op=replace,path=/policy,value="file://foo.json"

错误:

An error occurred (BadRequestException) when calling the UpdateRestApi operation: Invalid policy document. Please check the policy syntax and ensure that Principals are valid.

foo.json

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:eu-west-1:123345455:cyxxxxxd/test1/*"
}
]
}

谁能帮助我如何使用AWS cli用json文件替换现有的策略?

感谢

必须stringfy如文档中所示,您的策略优先。

strinfigied=$(jq tostring foo.json)
aws apigateway update-rest-api --rest-api-id cyasdze47d --patch-operations op=replace,path=/policy,value=${strinfigied}