public static void CreatePolicyIfNotExists(IAmazonIdentityManagementService iamClient, string policyName, string policyDocument, string roleName)
{
if (DoesRoleHavePolicy(iamClient, policyName, roleName))
{
return;
}
AutoResetEvent ars = new AutoResetEvent(false);
Exception responseException = new Exception();
iamClient.PutRolePolicyAsync(new PutRolePolicyRequest()
{
PolicyName = policyName,
PolicyDocument = policyDocument,
RoleName = roleName
}, (response) =>
{
responseException = response.Exception;
ars.Set();
}, new AsyncOptions { ExecuteCallbackOnMainThread = false });
ars.WaitOne();
Assert.IsNull(responseException);
}