Use SetSecurityGroups with a CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use SetSecurityGroups with a CLI

The following code examples show how to use SetSecurityGroups.

CLI
AWS CLI

To associate a security group with a load balancer

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

Command:

aws elbv2 set-security-groups --load-balancer-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188 --security-groups sg-5943793c

Output:

{ "SecurityGroupIds": [ "sg-5943793c" ] }
PowerShell
Tools for PowerShell

Example 1: This example adds security group 'sg-07c3414abb8811cbd' to the specified Load balancer.

Set-ELB2SecurityGroup -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -SecurityGroup 'sg-07c3414abb8811cbd'

Output:

sg-07c3414abb8811cbd
  • For API details, see SetSecurityGroups in AWS Tools for PowerShell Cmdlet Reference.