0

我試圖通過創建一個AWS CLI管理的策略:MalformedPolicyDocument錯誤而創建IAM策略

POLICY=' 
{ 
    "Version":"2012-10-17", 
    "Statement": 
    [{ 
    "Effect":"Allow", 
    "Action": 
    [ 
     "cloudformation:*" 
    ], 
    "Resource":"*" 
    }, 
    { 
    "Effect":"Deny", 
    "Action": 
    [ 
     "cloudformation:UpdateStack", 
     "cloudformation:DeleteStack" 
    ], 
    "Resource": "'${arn}'" 
    }] 
}' 

# Create policy if not already created 
[ $(aws iam list-policies | grep -ce CloudFormation-policy-${StackName}) -eq 0 ] && (aws iam create-policy --policy-name CloudFormation-policy-${StackName} --policy-document "'${POLICY}'") 

當我運行該腳本,我得到這個錯誤:

An error occurred (MalformedPolicyDocument) when calling the CreatePolicy operation: Syntax errors in policy. 

我不能找出錯誤的位置。 有什麼想法?

+0

你試圖從CLI跑的?您是否在AWS控制檯中驗證了這一點?我的猜測是這個問題是由於單引號與雙引號。 – kosa

+0

是的,它來自CLI。 當我做'回聲「‘$ {}政策’」'我得到了簡單的報價 – Somar

+0

哪個OS的CLI是運行在JSON? Windows還是Linux或Mac? – kosa

回答

1

每個操作系統都有自己的治療單引號VS雙引號逃逸,按AWS CLI documentation方式:

When passing in large blocks of data, you might find it easier to save the JSON to a file and reference it from the command line. JSON data in a file is easier to read, edit, and share with others.

Quoting Strings的做法可能不是最好的選擇,同時通過JSON數據,而是使用Loading parameters from file approach