AWS 문서 AWS SDK SDK 예제
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
CreatePolicy
AWS SDKOR와 함께 사용 CLI
다음 코드 예제는 CreatePolicy
의 사용 방법을 보여 줍니다.
- .NET
-
- AWS SDK for .NET
-
참고
더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Creates a new AWS Organizations Policy. /// </summary> public class CreatePolicy { /// <summary> /// Initializes the AWS Organizations client object, uses it to /// create a new Organizations Policy, and then displays information /// about the newly created Policy. /// </summary> public static async Task Main() { IAmazonOrganizations client = new AmazonOrganizationsClient(); var policyContent = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\" : [{" + " \"Action\" : [\"s3:*\"]," + " \"Effect\" : \"Allow\"," + " \"Resource\" : \"*\"" + "}]" + "}"; try { var response = await client.CreatePolicyAsync(new CreatePolicyRequest { Content = policyContent, Description = "Enables admins of attached accounts to delegate all Amazon S3 permissions", Name = "AllowAllS3Actions", Type = "SERVICE_CONTROL_POLICY", }); Policy policy = response.Policy; Console.WriteLine($"{policy.PolicySummary.Name} has the following content: {policy.Content}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
-
자세한 API 내용은 CreatePolicy AWS SDK for .NETAPI참조를 참조하십시오.
-
- CLI
-
- AWS CLI
-
예 1: 정책의 텍스트 소스 파일을 사용하여 JSON 정책을 만들려면
다음 예제는 라는 이름의 서비스 제어 정책 (SCP) 을 만드는 방법을 보여줍니다
AllowAllS3Actions
. 정책 콘텐츠는policy.json
이라는 로컬 컴퓨터에 있는 파일에서 가져온 것입니다.aws organizations create-policy --content
file://policy.json
--nameAllowAllS3Actions,
--typeSERVICE_CONTROL_POLICY
--description"Allows delegation of all S3 actions"
출력에는 새 정책에 대한 세부 정보가 포함된 정책 객체가 포함됩니다.
{ "Policy": { "Content": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"*\"]}]}", "PolicySummary": { "Arn": "arn:aws:organizations::o-exampleorgid:policy/service_control_policy/p-examplepolicyid111", "Description": "Allows delegation of all S3 actions", "Name": "AllowAllS3Actions", "Type":"SERVICE_CONTROL_POLICY" } } }
예 2: 정책을 매개변수로 사용하여 JSON 정책 생성하기
다음 예제는 정책 콘텐츠를 파라미터에 JSON 문자열로 포함하여 동일한 SCP 정책을 생성하는 방법을 보여줍니다. 파라미터에서 문자열을 큰 따옴표로 묶은 리터럴로 취급하도록 하려면 큰따옴표 앞의 백슬래시로 문자열을 이스케이프 처리해야 합니다.
aws organizations create-policy --content "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"*\"]}]}" --name
AllowAllS3Actions
--typeSERVICE_CONTROL_POLICY
--description"Allows delegation of all S3 actions"
조직에서 정책을 만들고 사용하는 방법에 대한 자세한 내용은 AWS Organizations 사용 설명서의 조직 정책 관리를 참조하세요.
-
자세한 API 내용은 AWS CLI 명령 CreatePolicy
참조를 참조하십시오.
-
- Python
-
- SDK파이썬용 (보토3)
-
참고
더 많은 정보가 있습니다. GitHub AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. def create_policy(name, description, content, policy_type, orgs_client): """ Creates a policy. :param name: The name of the policy. :param description: The description of the policy. :param content: The policy content as a dict. This is converted to JSON before it is sent to AWS. The specific format depends on the policy type. :param policy_type: The type of the policy. :param orgs_client: The Boto3 Organizations client. :return: The newly created policy. """ try: response = orgs_client.create_policy( Name=name, Description=description, Content=json.dumps(content), Type=policy_type, ) policy = response["Policy"] logger.info("Created policy %s.", name) except ClientError: logger.exception("Couldn't create policy %s.", name) raise else: return policy
-
자세한 API AWS SDK내용은 Python (Boto3) API 참조를 참조하십시오 CreatePolicy.
-