You can setup a config file to attach existing security groups in .ebextensions
FILE: ./.ebextensions/ec2-securitygroup.config
option_settings:
aws:autoscaling:launchconfiguration:
SecurityGroups: name-of-security-group-1, name-of-security-group-2
NOTE: Do not use the Group Name or Group ID, its the Name field/column
DOCS: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalinglaunchconfiguration
SecurityGroups
Lists the Amazon EC2 security groups to assign to the EC2 instances in the Auto Scaling group in order to define firewall rules for the instances.
You can provide a single string of comma-separated values that contain the name of existing Amazon EC2 security groups or references to AWS::EC2::SecurityGroup resources created in the template. Security group names are case sensitive.
If you use Amazon Virtual Private Cloud (Amazon VPC) with Elastic Beanstalk so that your instances are launched within a virtual private cloud (VPC), specify security group IDs instead of security group names.
elasticbeanstalk-default