Use ApplySecurityGroupsToLoadBalancer with a CLI - AWS SDK Code Examples

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

Use ApplySecurityGroupsToLoadBalancer with a CLI

The following code examples show how to use ApplySecurityGroupsToLoadBalancer.

CLI
AWS CLI

To associate a security group with a load balancer in a VPC

This example associates a security group with the specified load balancer in a VPC.

Command:

aws elb apply-security-groups-to-load-balancer --load-balancer-name my-load-balancer --security-groups sg-fc448899

Output:

{ "SecurityGroups": [ "sg-fc448899" ] }
PowerShell
Tools for PowerShell

Example 1: This example replaces the current security group for the specified load balancer with the specified security group.

Join-ELBSecurityGroupToLoadBalancer -LoadBalancerName my-load-balancer -SecurityGroup sg-87654321

Output:

sg-87654321

Example 2: To keep the current security group and specify an additional security group, specify both the existing and new security groups.

Join-ELBSecurityGroupToLoadBalancer -LoadBalancerName my-load-balancer -SecurityGroup @("sg-12345678", "sg-87654321")

Output:

sg-12345678 sg-87654321