Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from alexcasalboni/boto3_getpolicy.py
Created August 20, 2017 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertomartin/a9c1e254fe4cdfea00c2922807637d00 to your computer and use it in GitHub Desktop.
Save bertomartin/a9c1e254fe4cdfea00c2922807637d00 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