Amazon EMR
Management Guide

Customize IAM Roles

You may want to customize IAM roles and permissions for your requirements. For example, if your application does not use EMRFS consistent view, you may not want to allow Amazon EMR to access Amazon DynamoDB. To customize permissions, we recommend that you create new roles and policies. Begin with the permissions in the managed policies for the default roles (for example, AmazonElasticMapReduceforEC2Role and AmazonElasticMapReduceRole). Then, copy and paste the contents to new policy statements, modify the permissions as appropriate, and attach the modified permissions policies to the roles that you create. You must have the appropriate IAM permissions to work with roles and policies. For more information, see Allow Users and Groups to Create and Modify Roles.

If you create a custom EMR role for EC2, follow the basic work flow, which automatically creates an instance profile of the same name. Amazon EC2 allows you to create instance profiles and roles with different names, but Amazon EMR does not support this configuration, and it results in an "invalid instance profile" error when you create the cluster.

Important

Inline policies are not automatically updated when service requirements change. If you create and attach inline policies, be aware that service updates might occur that suddenly cause permissions errors. For more information, see Managed Policies and Inline Policies in the IAM User Guide and Specify Custom IAM Roles When You Create a Cluster.

For more information about working with IAM roles, see the following topics in the IAM User Guide:

Specify Custom IAM Roles When You Create a Cluster

You specify the service role for Amazon EMR and the role for the Amazon EC2 instance profile when you create a cluster. The user who is creating clusters needs permissions to retrieve and assign roles to Amazon EMR and EC2 instances. Otherwise, a User account is not authorized to call EC2 error occurs. For more information, see Allow Users and Groups to Create and Modify Roles.

Use the Console to Specify Custom Roles

When you create a cluster, you can specify a custom service role for Amazon EMR, a custom role for the EC2 instance profile, and a custom Auto Scaling role using Advanced options. When you use Quick options, the default service role and the default role for the EC2 instance profile are specified. For more information, see Use Default IAM Roles and Managed Policies.

To specify custom IAM roles using the console

  1. Open the Amazon EMR console at https://console.aws.amazon.com/elasticmapreduce/.

  2. Choose Create cluster, Go to advanced options.

  3. Choose the cluster settings appropriate for your application until you reach Security Options.

    Under Permissions, the Default roles for Amazon EMR are selected.

  4. Choose Custom.

  5. For each role type, select a role from the list. Only roles within your account that have the appropriate trust policy for that role type are listed.

  6. Choose other options as appropriate for your cluster and then choose Create Cluster.

Use the AWS CLI to Specify Custom Roles

You can specify a service role and a role for the EC2 instance profile using options with the create-cluster command from the AWS CLI. Use the --service-role option to specify the service role. Use the InstanceProfile argument of the --ec2-attributes option to specify the role for the EC2 instance profile.

You can use these options to specify default roles explicitly rather than using the --use-default-roles option. The --use-default-roles option specifies the service role and the role for the EC2 instance profile defined in the CLI configuration file, which you can update to reflect your custom roles. For more information, see Use Default IAM Roles and Managed Policies.

The Auto Scaling role is specified using a separate option, --auto-scaling-role. For more information, see Using Automatic Scaling in Amazon EMR.

To specify custom IAM roles using the AWS CLI

  • The following command specifies the custom service role, MyEMRServiceRole, and a custom role for the EC2 instance profile, MyEC2RoleForEMR, when launching a cluster. This example uses the default Amazon EMR role.

    Note

    Linux line continuation characters (\) are included for readability. They can be removed or used in Linux commands. For Windows, remove them or replace with a caret (^).

    aws emr create-cluster --name "Test cluster" --release-label emr-5.19.0 \ --applications Name=Hive Name=Pig --service-role MyEMRServiceRole \ --ec2-attributes InstanceProfile=MyEC2RoleForEMR,\ KeyName=myKey --instance-type m4.large --instance-count 3