Add an instance to a security group

Last Updated: Jul 25, 2017

Description

When adding an instance to a specified security group, consider the following:

  • This operation can only be performed for instances in Stopped or Running status.
  • Each instance can be attached to a maximum of 5 security groups.
  • Each security group can have up to 1000 instances.

Request parameters

Name Type Required Description
Action String Yes Value: JoinSecurityGroup.
InstanceId String Yes The specified instance ID.
SecurityGroupId String Yes The security group ID.

Return parameters

All parameters are public return parameters. For details, refer to Public Return Parameters.

Error code

Error Code Description Http status code Meaning
InvalidInstanceId.NotFound The specified InstanceId does not exist. 404 The specified InstanceId does not exist.
MissingParameter The input parameter InstanceId that is mandatory for processing this request is not supplied. 400 InstanceId value is missing.
InvalidSecurityGroupId.NotFound The specified SecurityGroupId does not exist. 404 The specified SecurityGroupId does not exist.
MissingParameter The input parameter SecurityGroupId that is mandatory for processing this request is not supplied. 400 SecurityGroupId value is missing.
InstanceSecurityGroupLimitExceeded Exceeding the allowed number of security groups that an instance can be in. 400 The instance has joined the maximum number of security groups allowed.
IncorrectInstanceStatus The current status of the resource does not support this operation. 403 The current status of the resource does not support this operation.
InstanceLockedForSecurity The specified operation is denied as your instance is locked for security reasons. 403 The operation is denied because the resource is locked for security reasons.
SecurityGroupInstanceLimitExceeded Exceeding the allowed number of instances of a security group. 403 The number of instances in a security group has reached the upper limit.
InvalidInstanceId.Mismatch Specified instance and security group are not in the same VPC. 403 The specified instance and security group do not belong to the same VPC, including following two special conditions:
  • The instance does not belong to a VPC type, while the security group does.
  • The instance belongs to a VPC type, while the security group does not.
InvalidInstanceId.AlreadyExists The specified instance already exists in the specified security group. 403 The specified security group already contains the specified instance.

Examples

Request example

  1. https://ecs.aliyuncs.com/?Action=JoinSecurityGroup
  2. &InstanceId= i-instance1
  3. &SecurityGroupId=F876FF7BA984
  4. &<Public Request Parameters>

Return example

XML format

  1. <JoinSecurityGroupResponse>
  2. <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E</RequestId>
  3. </JoinSecurityGroupResponse>

JSON format

  1. {
  2. "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
  3. }
Thank you! We've received your feedback.