How to add custom security groups to beanstalk?

How to add custom security groups to beanstalk?
Photo by Flex Point Security / Unsplash

.ebextensions can help you attach custom security groups to the instance.

  • Create a new security group, make sure to name the security group appropriately. You can add your custom inbound and outbound rules to the configuration. Let us name it demo-security-group, make sure to use the Security Group Name and not the Name attribute.
  • Create a file inside the .ebextensions , let us name it security_group.config and put the following content
option_settings:
  - namespace: aws:autoscaling:launchconfiguration
    option_name: SecurityGroups
    value: demo-security-group
.ebextensions/security_group.config
  • Now when you would deploy your code beanstalk environment, all your instances would have the demo-security-group attached to them
  • In order to add multiple security groups, you can add them as comma-separated-values, For example, you have 2 security groups, demo-security-group,another-security-group then add them in a single line.
option_settings:
  - namespace: aws:autoscaling:launchconfiguration
    option_name: SecurityGroups
    value: demo-security-group,another-security-group
.ebextensions/security_group.config