MalformedPolicyDocument error while creating an IAM Policy

Viewed 4705

I'm trying to create a managed policy by AWS CLI:

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}'")

When I run the script I get this error:

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

I can't figure out where the error is. Any idea?

1 Answers
Related