Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use AddRoleToInstanceProfile
with an Amazon SDK or command line tool
The following code examples show how to use AddRoleToInstanceProfile
.
- CLI
-
- Amazon CLI
-
To add a role to an instance profile
The following add-role-to-instance-profile
command adds the role named S3Access
to the instance profile named Webserver
.
aws iam add-role-to-instance-profile \
--role-name S3Access \
--instance-profile-name Webserver
This command produces no output.
To create an instance profile, use the create-instance-profile
command.
For more information, see Using an IAM role to grant permissions to applications running on Amazon EC2 instances in the Amazon IAM User Guide.
- PowerShell
-
- Tools for PowerShell
-
Example 1: This command adds the role named S3Access
to an existing instance profile named webserver
.
To create the instance profile, use the New-IAMInstanceProfile
command. After you create the instance profile and associate it with a role using this command, you can attach it to an EC2 instance. To do that, use the New-EC2Instance
cmdlet with either the InstanceProfile_Arn
or the InstanceProfile-Name
parameter to launch the new instance.
Add-IAMRoleToInstanceProfile -RoleName "S3Access" -InstanceProfileName "webserver"
For a complete list of Amazon SDK developer guides and code examples, see
Using IAM with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.