# Newb - Rule If/Then Question

**URL:** <https://community.auth0.com/t/newb-rule-if-then-question/32031>\
**Category:** Get Help\
**Tags:** saml2, rules\
**Created:** [October 8, 2019, 8:42pm UTC](https://community.auth0.com/t/newb-rule-if-then-question/32031 "2019-10-08T20:42:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![auth.hero](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth.hero/32/12842_2.png) [@auth.hero](https://community.auth0.com/u/auth.hero)\
**Post date:** [October 8, 2019, 8:42pm UTC](https://community.auth0.com/t/newb-rule-if-then-question/32031/1 "2019-10-08T20:42:07Z")

</div>

I got SAML2 working to AWS IAM with Auth0 as my IDP, with a single role. Now, I am trying to implement rules to assign different AWS roles based on user app metadata. I have it working but I am wondering if this is the most efficient route. Thoughts?

```auto
function (user, context, callback) {
	console.log('[before] user.app_metadata: ' + user.app_metadata.aws_role);
  
  user.app_metadata = user.app_metadata || {};

  if (user.app_metadata.aws_role === "AWS-FullAdmin") {
    user.awsRole = 'arn:aws:iam:::role/Auth0-FullAdmin,arn:aws:iam::111:saml-provider/Auth0_SAML_Provider';
  }
if (user.app_metadata.aws_role === "AWS-ReadOnlyAccounts") {
    user.awsRole = 'arn:aws:iam::111:role/Auth0-ReadOnlyAccounts,arn:aws:iam::111:saml-provider/Auth0_SAML_Provider';
  	console.log('awsrole1 is : ' + user.awsRole);
  }
  
  user.awsRoleSession = user.name;
  context.samlConfiguration.mappings = {
    'https://aws.amazon.com/SAML/Attributes/Role': 'awsRole',
    'https://aws.amazon.com/SAML/Attributes/RoleSessionName': 'awsRoleSession'
  };

  callback(null, user, context);

}

```

I’m just trying something simple, which is: if user has app metadata aws\_role value of AWS-FullAdmin, then pass the Admin specific AWS attribute. If aws\_role is ReadOnly, pass the read only attribute.

---

<div class="post-metadata">

**Author:** ![thomas.osborn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thomas.osborn/32/22282_2.png) [@thomas.osborn](https://community.auth0.com/u/thomas.osborn)\
**Post date:** [November 3, 2019, 5:23am UTC](https://community.auth0.com/t/newb-rule-if-then-question/32031/2 "2019-11-03T05:23:02Z")

</div>

Hello [auth.hero](http://community.auth0.com/u/auth.hero), and great name! 🎉

That seems efficient to me. Was there any part you were particular concerned might be inefficient? In general, the only efficiency concerns in rules are that you avoid calling the management API too much (which you are not doing), making them too large (but your rule is very small), or making sure they end as early as possible / run quickly (which this should do).

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 8, 2024, 8:55am UTC](https://community.auth0.com/t/newb-rule-if-then-question/32031/3 "2024-01-08T08:55:38Z")

</div>

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)
