- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
AssociateIamInstanceProfileCommand
Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { EC2Client, AssociateIamInstanceProfileCommand } from "@aws-sdk/client-ec2"; // ES Modules import
// const { EC2Client, AssociateIamInstanceProfileCommand } = require("@aws-sdk/client-ec2"); // CommonJS import
const client = new EC2Client(config);
const input = { // AssociateIamInstanceProfileRequest
IamInstanceProfile: { // IamInstanceProfileSpecification
Arn: "STRING_VALUE",
Name: "STRING_VALUE",
},
InstanceId: "STRING_VALUE", // required
};
const command = new AssociateIamInstanceProfileCommand(input);
const response = await client.send(command);
// { // AssociateIamInstanceProfileResult
// IamInstanceProfileAssociation: { // IamInstanceProfileAssociation
// AssociationId: "STRING_VALUE",
// InstanceId: "STRING_VALUE",
// IamInstanceProfile: { // IamInstanceProfile
// Arn: "STRING_VALUE",
// Id: "STRING_VALUE",
// },
// State: "associating" || "associated" || "disassociating" || "disassociated",
// Timestamp: new Date("TIMESTAMP"),
// },
// };
Example Usage
Loading code editorLoading code editor
AssociateIamInstanceProfileCommand Input
See AssociateIamInstanceProfileCommandInput for more details
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
IamInstanceProfile Required | IamInstanceProfileSpecification | undefined | The IAM instance profile. |
InstanceId Required | string | undefined | The ID of the instance. |
AssociateIamInstanceProfileCommand Output
See AssociateIamInstanceProfileCommandOutput for details
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
IamInstanceProfileAssociation | IamInstanceProfileAssociation | undefined | Information about the IAM instance profile association. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
EC2ServiceException | Base exception class for all service exceptions from EC2 service. |