I need to add multiple securityGroups to my EB-Environment. This is a part of my template for EB Environment:
Type: 'AWS::ElasticBeanstalk::Environment'
Properties:
...
OptionSettings:
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value: ...
Use SecurityGroups 2x
but the latter overrides the preceding value
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value:
- !Sub ${EnvironmentPrefix}-ssh
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value:
- launch-wizard-1
Use an array
but it ends up with an error:
Value of property Value must be of type String
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value:
- !Sub ${EnvironmentPrefix}-ssh
- launch-wizard-1
How can set multiple SecurityGroups for 'AWS::ElasticBeanstalk::Environment'?
According to the documentation you can pass a comma separated list of security groups as the value.
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. If you use Amazon VPC with Elastic Beanstalk so that your instances are launched within a virtual private cloud (VPC), specify security group IDs instead of a security group name.
So:
Type: 'AWS::ElasticBeanstalk::Environment'
Properties:
...
OptionSettings:
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value: sg-1,sg-2,sg-3