:doc:`ElasticLoadBalancingv2 <../../elbv2>` / Client / set_security_groups

*******************
set_security_groups
*******************



.. py:method:: ElasticLoadBalancingv2.Client.set_security_groups(**kwargs)

  

  Associates the specified security groups with the specified Application Load Balancer or Network Load Balancer. The specified security groups override the previously associated security groups.

   

  You can't perform this operation on a Network Load Balancer unless you specified a security group for the load balancer when you created it.

   

  You can't associate a security group with a Gateway Load Balancer.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/elasticloadbalancingv2-2015-12-01/SetSecurityGroups>`_  


  **Request Syntax**
  ::

    response = client.set_security_groups(
        LoadBalancerArn='string',
        SecurityGroups=[
            'string',
        ],
        EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic='on'|'off'
    )
    
  :type LoadBalancerArn: string
  :param LoadBalancerArn: **[REQUIRED]** 

    The Amazon Resource Name (ARN) of the load balancer.

    

  
  :type SecurityGroups: list
  :param SecurityGroups: **[REQUIRED]** 

    The IDs of the security groups.

    

  
    - *(string) --* 

    

  :type EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic: string
  :param EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic: 

    Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through Amazon Web Services PrivateLink. Applies only if the load balancer has an associated security group. The default is ``on``.

    

  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'SecurityGroupIds': [
              'string',
          ],
          'EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic': 'on'|'off'
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **SecurityGroupIds** *(list) --* 

        The IDs of the security groups associated with the load balancer.

        
        

        - *(string) --* 
    
      

      - **EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic** *(string) --* 

        Indicates whether to evaluate inbound security group rules for traffic sent to a Network Load Balancer through Amazon Web Services PrivateLink.

        
  
  **Exceptions**
  
  *   :py:class:`ElasticLoadBalancingv2.Client.exceptions.LoadBalancerNotFoundException`

  
  *   :py:class:`ElasticLoadBalancingv2.Client.exceptions.InvalidConfigurationRequestException`

  
  *   :py:class:`ElasticLoadBalancingv2.Client.exceptions.InvalidSecurityGroupException`

  

  **Examples**

  This example associates the specified security group with the specified load balancer.
  ::

    response = client.set_security_groups(
        LoadBalancerArn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188',
        SecurityGroups=[
            'sg-5943793c',
        ],
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        'SecurityGroupIds': [
            'sg-5943793c',
        ],
        'ResponseMetadata': {
            '...': '...',
        },
    }

  