Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Last active August 20, 2017 03:53
Show Gist options
  • Save alexcasalboni/07414d62290828ea03a14b4bf2157fd1 to your computer and use it in GitHub Desktop.
Save alexcasalboni/07414d62290828ea03a14b4bf2157fd1 to your computer and use it in GitHub Desktop.
AWS IAM Policy body with Python and boto3
import boto3
iam = boto3.resource('iam')
def get_policy_body(arn, version_id=None):
""" Return IAM Policy JSON body """
if version_id:
version = iam.PolicyVersion(arn, version_id)
else:
policy = iam.Policy(arn)
version = policy.default_version
return version.document
POLICY_ARN = "YOUR_POLICY_ARN"
body = get_policy_body(POLICY_ARN) # already a dict
print("Policy body: %s" % body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment