AssociateSecurityGroupVpcCommand

Associates a security group with another VPC in the same Region. This enables you to use the same security group with network interfaces and instances in the specified VPC.

  • The VPC you want to associate the security group with must be in the same Region.

  • You can associate the security group with another VPC if your account owns the VPC or if the VPC was shared with you.

  • You must own the security group and the VPC that it was created in.

  • You cannot use this feature with default security groups.

  • You cannot use this feature with the default VPC.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { EC2Client, AssociateSecurityGroupVpcCommand } from "@aws-sdk/client-ec2"; // ES Modules import
// const { EC2Client, AssociateSecurityGroupVpcCommand } = require("@aws-sdk/client-ec2"); // CommonJS import
const client = new EC2Client(config);
const input = { // AssociateSecurityGroupVpcRequest
  GroupId: "STRING_VALUE", // required
  VpcId: "STRING_VALUE", // required
  DryRun: true || false,
};
const command = new AssociateSecurityGroupVpcCommand(input);
const response = await client.send(command);
// { // AssociateSecurityGroupVpcResult
//   State: "associating" || "associated" || "association-failed" || "disassociating" || "disassociated" || "disassociation-failed",
// };

AssociateSecurityGroupVpcCommand Input

Parameter
Type
Description
GroupId
Required
string | undefined

A security group ID.

VpcId
Required
string | undefined

A VPC ID.

DryRun
boolean | undefined

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

AssociateSecurityGroupVpcCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
State
SecurityGroupVpcAssociationState | undefined

The state of the association.

Throws

Name
Fault
Details
EC2ServiceException
Base exception class for all service exceptions from EC2 service.