This topic describes how to create an instance RAM role, attach a policy to the RAM role, and then attach the RAM role to an Elastic Compute Service (ECS) instance by using the Resource Access Management (RAM) and ECS consoles.
Prerequisites
- The ECS instance to which you want to attach a RAM role is located in a virtual private cloud (VPC).
- A RAM user is already authorized to use the instance RAM role if you use the RAM user to perform the procedure described in this topic. For more information, see Authorize a RAM user to manage an instance RAM role.
Background information
If you have attached an instance RAM role to an ECS instance and want to access the APIs of other Alibaba Cloud services from applications that are deployed on the instance, you must obtain a temporary authorization token for the instance RAM role by using the instance metadata. For more information, see Use an instance RAM role by calling API operations.
Procedure
Step 1: Create an instance RAM role
Perform the following operations to create an instance RAM role in the RAM console:
- Log on to the RAM console by using your Alibaba Cloud account.
- In the left-side navigation pane, choose .
- On the Roles page, click Create Role.
- In the Create Role panel, select Alibaba Cloud Service as the trusted entity and click Next. Select Alibaba Cloud Service to authorize ECS instances to access or manage your cloud resources. After you select Alibaba Cloud Service for the RAM role, you can attach the RAM role to ECS instances.NoteIf you select Alibaba Cloud Account for a RAM role, you must click Edit Trust Policy on the Trust Policy Management tab to manually add the following policy for ECS after the RAM role is created:
"Service": [ "ecs.aliyuncs.com" ]
- Select Normal Service Role for the Role Type parameter.
- Specify the RAM Role Name and Note parameters.
- Select Elastic Compute Service as the trusted service.
- Click OK.
- Click Close.

Step 2: Attach a policy to the instance RAM role
Perform the following operations to attach a system or custom policy to the instance RAM role in the RAM console:
- Log on to the RAM console by using your Alibaba Cloud account.
- (Optional) Create a custom policy if you do not want to use a system policy. For more information, see the "Create a custom policy" section in Control access to resources by using RAM users.
- In the left-side navigation pane, choose .
- On the Roles page, find the RAM role to which you want to grant permissions and click Input and Attach in the Actions column.
- In the Add Permissions panel, set Type to System Policy or Custom Policy and enter a policy name.
- Click OK.
- Click Close.
Step 3: Attach the instance RAM role to an ECS instance
- Log on to the ECS console.
- In the left-side navigation pane, choose .
- In the top navigation bar, select a region.
- Find the ECS instance to which you want to attach the instance RAM role and choose in the Actions column.
- In the Attach/Detach RAM Role dialog box, select the instance RAM role from the RAM Role drop-down list and click OK.
You can also select the instance RAM role from the RAM Role drop-down list in the System Configurations (Optional) step when you create an ECS instance. For more information, see Create an instance by using the wizard.