For default one, you can use the below commands:
aws ec2 modify-instance-attribute --instance-id i-123 --groups sg-1 sg-2 ..
And if the instance has more than one network interface, then use the below commands:
aws ec2 modify-network-interface-attribute --groups sg-1 sg-2 --network-interface-id eni-1
For more, you can read here.
Want to learn more about AWS? Come & join: AWS Certification