Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Get an IAM policy version using an Amazon SDK
The following code example shows how to get an IAM policy version.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code examples:
- Python
-
- SDK for Python (Boto3)
-
def get_default_policy_statement(policy_arn):
"""
Gets the statement of the default version of the specified policy.
:param policy_arn: The ARN of the policy to look up.
:return: The statement of the default policy version.
"""
try:
policy = iam.Policy(policy_arn)
# To get an attribute of a policy, the SDK first calls get_policy.
policy_doc = policy.default_version.document
policy_statement = policy_doc.get('Statement', None)
logger.info("Got default policy doc for %s.", policy.policy_name)
logger.info(policy_doc)
except ClientError:
logger.exception("Couldn't get default policy statement for %s.", policy_arn)
raise
else:
return policy_statement
For a complete list of Amazon SDK developer guides and code examples, see
Using IAM with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.