Example #1
0
        public static void AttachRolePolicy()
        {
            var               client      = new AmazonIdentityManagementServiceClient();
            string            policy      = GenerateRolePolicyDocument();
            CreateRoleRequest roleRequest = new CreateRoleRequest()
            {
                RoleName = "tester",
                AssumeRolePolicyDocument = policy
            };

            var request = new AttachRolePolicyRequest()
            {
                PolicyArn = "arn:aws:iam::123456789:policy/DemoEC2Permissions",
                RoleName  = "tester"
            };

            try
            {
                var response = client.AttachRolePolicy(request);
                Console.WriteLine("Policy DemoEC2Permissions attached to Role TestUser");
            }
            catch (NoSuchEntityException)
            {
                Console.WriteLine
                    ("Policy 'DemoEC2Permissions' does not exist");
            }
            catch (InvalidInputException)
            {
                Console.WriteLine
                    ("One of the parameters is incorrect");
            }
        }
Example #2
0
        public void IdentityManagementServiceAttachRolePolicy()
        {
            #region 3e1b8c7c-99c8-4fc4-a20c-131fe3f22c7e

            var client   = new AmazonIdentityManagementServiceClient();
            var response = client.AttachRolePolicy(new AttachRolePolicyRequest
            {
                PolicyArn = "arn:aws:iam::aws:policy/ReadOnlyAccess",
                RoleName  = "ReadOnlyRole"
            });


            #endregion
        }