Muhammad Awais
Muhammad Awais

Reputation: 93

Move multiple security groups from one VPC to another

I have around 20 security groups, that I need to migrate to a new VPC in the same region? Is there a way to do it from console? If not how to do it from CLI?

Upvotes: 0

Views: 2063

Answers (3)

Praneeta Paradkar
Praneeta Paradkar

Reputation: 1

you can make a copy of the security group and select the desired VPC. But still you have to do this 20 times via the UI - so automation might be a better route.

enter image description here

Upvotes: 0

Marcin
Marcin

Reputation: 238189

As @Chris said, you can't easily move them. But you can get detailed list of your SGs.

To list all the groups for a given VPC you can use describe-security-groups CLI. For example

aws ec2 describe-security-groups \
     --filters Name=vpc-id,Values=vpc-0f3a07c98a37d224c

would give something of the following (not all shown):

{                                                                                                                                                                                              
    "SecurityGroups": [                                                                                                                                                                        
        {                                                                                                                                                                                      
            "Description": "launch-wizard-1 created 2020-07-01T12:52:42.308+08:00",                                                                                                            
            "GroupName": "launch-wizard-1",                                                                                                                                                    
            "IpPermissions": [                                                                                                                                                                 
                {                                                                                                                                                                              
                    "FromPort": 22,                                                                                                                                                            
                    "IpProtocol": "tcp",                                                                                                                                                       
                    "IpRanges": [                                                                                                                                                              
                        {                                                                                                                                                                      
                            "CidrIp": "0.0.0.0/0"                                                                                                                                              
                        }                                                                                                                                                                      
                    ],                                                                                                                                                                         
                    "Ipv6Ranges": [],                                                                                                                                                          
                    "PrefixListIds": [],                                                                                                                                                       
                    "ToPort": 22,                                                                                                                                                              
                    "UserIdGroupPairs": []                                                                                                                                                     
                }                                                                                                                                                                              
            ],                                                                                                                                                                                 
            "OwnerId": "044050374169",                                                                                                                                                         
            "GroupId": "sg-01a76edeabb0a8f69",                                                                                                                                                 
            "IpPermissionsEgress": [                                                                                                                                                           
                {                                                                                                                                                                           
                    "IpProtocol": "-1",                                                                                                                                                     
                    "IpRanges": [                                                                                                                                                           
                        {                                                                                                                                                                   
                            "CidrIp": "0.0.0.0/0"                                                                                                                                           
                        }                                                                                                                                                                   
                    ],                                                                                                                                                                      
                    "Ipv6Ranges": [],                                                                                                                                                       
                    "PrefixListIds": [],                                                                                                                                                    
                    "UserIdGroupPairs": []                                                                                                                                                  
                }                                                                                                                                                                           
            ],                                                                                                                                                                              
            "VpcId": "vpc-0f3a07c98a37d224c"                                                                                                                                                
        }
}

This would greatly help re-creating them in CloudFormation or using CLI in other vpc.

Upvotes: 1

Chris Williams
Chris Williams

Reputation: 35188

There is no way to move the same security groups from one VPC to another VPC.

Unfortunately, your only option is to move them again. I would suggest when you do this you create them via infrastructure as code using a tool such as CloudFormation or Terraform.

By doing this you will easily be able to replicate the moving of security groups between VPCs in the future.

Upvotes: 0

Related Questions