title: AWS CLI retrieve the ARN of the newly created policy
body: <p>I want to create an IAM policy and attach it to some IAM role using AWS command-line interface.</p>
  
  <p>Creating policy is quite simple:</p>
  
  <pre><code>aws iam create-policy --policy-name "${policy_name}" --policy-document file://policy.json
  </code></pre>
  
  <p>But to attach the newly created policy to the target role I must know the ARN of the policy:</p>
  
  <pre><code>aws iam attach-role-policy --role-name "${role_name}" --policy-arn "${policy_arn}"
  </code></pre>
  
  <p>What is the correct way to retrieve ARN of the newly created policy?</p>
  
  <p>Right now I'm construcing <code>policy_arn</code> myself using <code>policy_name</code> and the <code>account_id</code>:</p>
  
  <pre><code>policy_arn=arn:aws:iam::"${account_id}":policy/"${policy_name}"
  </code></pre>
  
  <p>This is how I retrieve the <code>account_id</code>:</p>
  
  <pre><code>account_id=$(aws ec2 describe-security-groups --query 'SecurityGroups[0].OwnerId' --output text)
  </code></pre>
  
  <p>However this feels quite hacky.</p>
  
  <p>Is there a better way to find out ARN of the created policy?</p>