Skip to content

associate_security_group_vpc async

associate_security_group_vpc(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_id: Optional[SecurityGroupId] = None,
    vpc_id: Optional[VpcId] = None,
    dry_run: Optional[Boolean] = None,
) -> AssociateSecurityGroupVpcResult

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.

  • You cannot use this feature with default security groups.

  • You cannot use this feature with the default VPC.

Parameters:

  • group_id (Optional[SecurityGroupId], default: None ) –

    A security group ID.

  • vpc_id (Optional[VpcId], default: None ) –

    A VPC ID.

  • dry_run (Optional[Boolean], default: None ) –

    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.

Raises:

Source code in docs_src/capo_ec2/_services/async_ec2.py
async def associate_security_group_vpc(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_id: Optional["capo_ec2.types.security_group_id.SecurityGroupId"] = None,
    vpc_id: Optional["capo_ec2.types.vpc_id.VpcId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.associate_security_group_vpc_result.AssociateSecurityGroupVpcResult":
    """<p>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.</p> <note> <ul> <li> <p>The VPC you want to associate the security group with must be in the same Region.</p> </li> <li> <p>You can associate the security group with another VPC if your account owns the VPC or if the VPC was shared with you.</p> </li> <li> <p>You must own the security group.</p> </li> <li> <p>You cannot use this feature with default security groups.</p> </li> <li> <p>You cannot use this feature with the default VPC.</p> </li> </ul> </note>

    Args:
        group_id: <p>A security group ID.</p>
        vpc_id: <p>A VPC ID.</p>
        dry_run: <p>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 <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.associate_security_group_vpc_request.AssociateSecurityGroupVpcRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.associate_security_group_vpc_result.AssociateSecurityGroupVpcResult"
    ]:
        import capo_ec2._operations.amazon_ec2.associate_security_group_vpc

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.associate_security_group_vpc.async_associate_security_group_vpc(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssociateSecurityGroupVpc")
    )
    input_: capo_ec2.types.associate_security_group_vpc_request.AssociateSecurityGroupVpcRequest = {}
    if group_id is not None:
        input_["group_id"] = group_id
    if vpc_id is not None:
        input_["vpc_id"] = vpc_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output