コード例 #1
0
        private static async Task AttachAdminPolicyToAdminGroup(IAmazonIdentityManagementService client,
                                                                CancellationToken token)
        {
            const string policyDocument =
                @"
                {
                    ""Version"": ""2012-10-17"",
                    ""Statement"": [
                        {
                            ""Effect"": ""Allow"",
                            ""Action"": ""*"",
                            ""Resource"": ""*""
                        }
                    ]
                }";

            CreatePolicyRequest request = new CreatePolicyRequest()
            {
                Description    = "Policy for Administrators",
                PolicyDocument = policyDocument,
                PolicyName     = "AllAccess"
            };

            CreatePolicyResponse response = await client.CreatePolicyAsync(request, token);

            //throw new NotImplementedException();
        }
コード例 #2
0
        public async Task <string> CreateIamPolicy(IAmazonIdentityManagementService iamClient, string policyName)
        {
            try
            {
                Console.WriteLine("Creating IAM Policy");
                CreatePolicyResponse response = await iamClient.CreatePolicyAsync(new CreatePolicyRequest()
                {
                    PolicyName     = policyName,
                    PolicyDocument = AwsResourceConstant.PolicyDocument,
                    Description    = "Created via AWS Timestream sample"
                });

                Console.WriteLine($"The ARN of the policy is :  {response.Policy.Arn}");

                // Wait for the policy to be available
                Thread.Sleep(2000);
                return(response.Policy.Arn);
            }
            catch (EntityAlreadyExistsException)
            {
                string accountId = new AmazonSecurityTokenServiceClient().GetCallerIdentityAsync(new GetCallerIdentityRequest()).Result.Account;
                return(String.Format("arn:aws:iam::{0}:policy/{1}", accountId, policyName));
            }
            catch (Exception e)
            {
                Console.WriteLine($"IAM policy creation failed: {e}");
                throw;
            }
        }
コード例 #3
0
 private Amazon.IdentityManagement.Model.CreatePolicyResponse CallAWSServiceOperation(IAmazonIdentityManagementService client, Amazon.IdentityManagement.Model.CreatePolicyRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Identity and Access Management", "CreatePolicy");
     try
     {
         #if DESKTOP
         return(client.CreatePolicy(request));
         #elif CORECLR
         return(client.CreatePolicyAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }