There are more AWS SDK examples available in the AWS Doc SDK Examples
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-groupssg-fc448899
Output:
{ "SecurityGroups": [ "sg-fc448899" ] }
-
For API details, see ApplySecurityGroupsToLoadBalancer
in AWS CLI Command Reference.
-
- 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
-
For API details, see ApplySecurityGroupsToLoadBalancer in AWS Tools for PowerShell Cmdlet Reference.
-