使用 Amazon 开发工具包创建 IAM policy 版本
以下代码示例显示如何创建 IAM policy 版本。
- Python
-
- 适用于 Python (Boto3) 的 SDK
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 def create_policy_version(policy_arn, actions, resource_arn, set_as_default): """ Creates a policy version. Policies can have up to five versions. The default version is the one that is used for all resources that reference the policy. :param policy_arn: The ARN of the policy. :param actions: The actions to allow in the policy version. :param resource_arn: The ARN of the resource this policy version applies to. :param set_as_default: When True, this policy version is set as the default version for the policy. Otherwise, the default is not changed. :return: The newly created policy version. """ policy_doc = { 'Version': '2012-10-17', 'Statement': [ { 'Effect': 'Allow', 'Action': actions, 'Resource': resource_arn } ] } try: policy = iam.Policy(policy_arn) policy_version = policy.create_version( PolicyDocument=json.dumps(policy_doc), SetAsDefault=set_as_default) logger.info( "Created policy version %s for policy %s.", policy_version.version_id, policy_version.arn) except ClientError: logger.exception("Couldn't create a policy version for %s.", policy_arn) raise else: return policy_version-
有关 API 详细信息,请参阅《Amazon SDK for Python(Boto3)API 参考》中的 CreatePolicyVersion。
-
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将 IAM 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。
创建策略
创建角色