Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change AWS ECS service's security groups

I would like to be able to modify the network configuration of an AWS ECS service. The interface has "Allowed VPC", "Allowed subnets", "Security Groups", and "Auto-assign public IP" at the top of the "Configure network" screen. However they cannot be modified. We have been using a common security group for some of the services. When creating one of the services we missed assigning the security group so a new one was created. This seems like something I should be able to go back and correct.

like image 805
user1686620 Avatar asked Sep 06 '19 18:09

user1686620


People also ask

How do I change the security group for ECS service?

You can change security group settings with console: Update service and select awsvpc version of template (typically latest). If you select different template version you will not see networking step. Follow service update wizard to select network and security groups.

Can we change default security group in AWS?

You can add or remove inbound and outbound rules for any default security group. You can't delete a default security group. If you try to delete a default security group, you see the following error: Client. CannotDelete: the specified group: "sg-51530134" name: "default" cannot be deleted by a user .

How do I find my ECS security group?

Log on to the ECS console. In the left-side navigation pane, choose Network & Security > Security Groups. In the top navigation bar, select a region. Find the security group to which you want to add instances and click Manage Instances in the Actions column.


2 Answers

You can change it if you use the AWS CLI.

aws ecs update-service --cluster ClusterName --service ServiceName --network-configuration file://c:\json\networkConfig.txt

Where your networkConfig.txt file contains

{
  "awsvpcConfiguration": {
    "subnets": ["subnet-***","subnet-***"],
    "securityGroups": ["sg-***"],
    "assignPublicIp": "ENABLED"
  }
}
like image 87
TheCodeMonk Avatar answered Oct 03 '22 17:10

TheCodeMonk


No, You can not change the security group of the fargate type ECS task, as the security group attach with manages resources. Like in case of ECS EC2 type task where you manage instances for the ECS so you can change the security group for the resources, go to EC2 instance -> modify resources -> modify SG but here is the case is different you do not have to manage as AWS belief container as services (cas).

Workaround:

  • Go to security group -> select associated fargate SG -> modify the rule

  • Launch another new fargate task and associate the desired SG for the fargate service.

enter image description here

like image 22
Adiii Avatar answered Oct 03 '22 18:10

Adiii