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
The following
apply-security-groups-to-load-balancerexample associates a security group with the specified load balancer in a VPC.aws elb apply-security-groups-to-load-balancer \ --load-balancer-namemy-load-balancer\ --security-groupssg-fc448899Output:
{ "SecurityGroups": [ "sg-fc448899" ] }For more information, see Configure security groups for your Classic Load Balancer in the Classic Load Balancers Guide.
-
For API details, see ApplySecurityGroupsToLoadBalancer
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
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-87654321Output:
sg-87654321Example 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 (V4).
-
- Tools for PowerShell V5
-
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-87654321Output:
sg-87654321Example 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 (V5).
-