public void IdentityManagementServiceAddRoleToInstanceProfile()
        {
            #region c107fac3-edb6-4827-8a71-8863ec91c81f

            var response = client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = "Webserver",
                RoleName            = "S3Access"
            });


            #endregion
        }
 private Amazon.IdentityManagement.Model.AddRoleToInstanceProfileResponse CallAWSServiceOperation(IAmazonIdentityManagementService client, Amazon.IdentityManagement.Model.AddRoleToInstanceProfileRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Identity and Access Management", "AddRoleToInstanceProfile");
     try
     {
         #if DESKTOP
         return(client.AddRoleToInstanceProfile(request));
         #elif CORECLR
         return(client.AddRoleToInstanceProfileAsync(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;
     }
 }
Exemplo n.º 3
0
        public void IdentityProfiles()
        {
            var profiles      = client.ListInstanceProfiles().InstanceProfiles;
            int originalCount = profiles.Count;

            AssertExtensions.ExpectException(() => client.GetInstanceProfile(new GetInstanceProfileRequest
            {
                InstanceProfileName = profileName
            }));

            var newProfile = client.CreateInstanceProfile(new CreateInstanceProfileRequest
            {
                InstanceProfileName = profileName,
                Path = path
            }).InstanceProfile;

            Assert.IsNotNull(newProfile);

            profiles = client.ListInstanceProfiles().InstanceProfiles;
            Assert.AreEqual(originalCount + 1, profiles.Count);

            var profile = client.GetInstanceProfile(new GetInstanceProfileRequest
            {
                InstanceProfileName = profileName
            }).InstanceProfile;

            Assert.IsNotNull(profile);

            AssertExtensions.ExpectException(() => client.ListInstanceProfilesForRole(new ListInstanceProfilesForRoleRequest
            {
                RoleName = roleName
            }));

            // add role to profile
            var newRole = client.CreateRole(new CreateRoleRequest
            {
                RoleName = roleName,
                Path     = path,
                AssumeRolePolicyDocument = TEST_ASSUME_ALLOW_POLICY
            }).Role;

            Assert.IsNotNull(newRole);

            client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = profileName,
                RoleName            = roleName
            });
            var roleProfiles = client.ListInstanceProfilesForRole(new ListInstanceProfilesForRoleRequest
            {
                RoleName = roleName
            }).InstanceProfiles;

            Assert.AreEqual(1, roleProfiles.Count);

            client.RemoveRoleFromInstanceProfile(new RemoveRoleFromInstanceProfileRequest
            {
                InstanceProfileName = profileName,
                RoleName            = roleName
            });
            roleProfiles = client.ListInstanceProfilesForRole(new ListInstanceProfilesForRoleRequest
            {
                RoleName = roleName
            }).InstanceProfiles;
            Assert.AreEqual(0, roleProfiles.Count);

            client.DeleteInstanceProfile(new DeleteInstanceProfileRequest
            {
                InstanceProfileName = profileName
            });

            AssertExtensions.ExpectException(() => client.DeleteInstanceProfile(new DeleteInstanceProfileRequest
            {
                InstanceProfileName = profileName
            }));

            profiles = client.ListInstanceProfiles().InstanceProfiles;
            Assert.AreEqual(originalCount, profiles.Count);
        }