翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
または AttachPolicy
で を使用する AWS SDK CLI
以下のコード例は、AttachPolicy
の使用方法を示しています。
- .NET
-
- AWS SDK for .NET
-
注記
詳細については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Shows how to attach an AWS Organizations policy to an organization, /// an organizational unit, or an account. /// </summary> public class AttachPolicy { /// <summary> /// Initializes the Organizations client object and then calls the /// AttachPolicyAsync method to attach the policy to the root /// organization. /// </summary> public static async Task Main() { IAmazonOrganizations client = new AmazonOrganizationsClient(); var policyId = "p-00000000"; var targetId = "r-0000"; var request = new AttachPolicyRequest { PolicyId = policyId, TargetId = targetId, }; var response = await client.AttachPolicyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully attached Policy ID {policyId} to Target ID: {targetId}."); } else { Console.WriteLine("Was not successful in attaching the policy."); } } }
-
API 詳細については、「 AWS SDK for .NET APIリファレンスAttachPolicy」の「」を参照してください。
-
- CLI
-
- AWS CLI
-
root、OU、またはアカウントにポリシーをアタッチするには
例 1
次の例は、サービスコントロールポリシー (SCP) を OU にアタッチする方法を示しています。
aws organizations attach-policy --policy-id
p-examplepolicyid111
--target-idou-examplerootid111-exampleouid111
例 2
次の例は、サービスコントロールポリシーをアカウントに直接アタッチする方法を示しています。
aws organizations attach-policy --policy-id
p-examplepolicyid111
--target-id333333333333
-
API 詳細については、AWS CLI 「 コマンドリファレンスAttachPolicy
」の「」を参照してください。
-
- Python
-
- SDK for Python (Boto3)
-
注記
詳細については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 def attach_policy(policy_id, target_id, orgs_client): """ Attaches a policy to a target. The target is an organization root, account, or organizational unit. :param policy_id: The ID of the policy to attach. :param target_id: The ID of the resources to attach the policy to. :param orgs_client: The Boto3 Organizations client. """ try: orgs_client.attach_policy(PolicyId=policy_id, TargetId=target_id) logger.info("Attached policy %s to target %s.", policy_id, target_id) except ClientError: logger.exception( "Couldn't attach policy %s to target %s.", policy_id, target_id ) raise
-
API 詳細については、「 for AWS SDKPython (Boto3) APIリファレンスAttachPolicy」の「」を参照してください。
-
開発者ガイドとコード例の完全なリスト AWS SDKについては、「」を参照してくださいAWS SDK AWS Organizations での の使用。このトピックには、開始方法に関する情報と以前のSDKバージョンに関する詳細も含まれています。
アクション
CreateAccount