Is it possible to update an existing EC2 security group from CloudFormation

amazon ec2amazon-cloudformationamazon-web-services

I have a manually created security group to access Redis, and I am creating a LAMP stack with AWS CloudFormation. I need to update the Amazon EC2 security group from Redis to allow access from this LAMP stack, but I want it to be updated through CloudFormation – is this possible?

Best Answer

Existing SecurityGroups can be updated using SecurityGroupIngress

For example:

"SecurityGroupRedisIngress": {
    "Type": "AWS::EC2::SecurityGroupIngress",
    "Properties" : {   
        "GroupId": "sg-123456789",
        "IpProtocol": "tcp",
        "FromPort": "6379",
        "ToPort": "6379",
        "CidrIp": "1.2.3.4/0"
    }
}