code: def create_gateway_security_group(
      ec2_client: botocore.client.BaseClient, project_id: str
  ) -> str:
      security_group_name = (
          "dstack_gw_sg_" + project_id.replace("-", "_").lower()
      )
  
      response = ec2_client.describe_security_groups(
          Filters=[
              {
                  "Name": "group-name",
                  "Values": [security_group_name],
              },
          ],
      )
      if response.get("SecurityGroups"):
          return response["SecurityGroups"][0]["GroupId"]
  
      security_group = ec2_client.create_security_group(
          Description="Generated by dstack",
          GroupName=security_group_name,
          TagSpecifications=[
              {
                  "ResourceType": "security-group",
                  "Tags": [
                      {"Key": "owner", "Value": "dstack"},
                      {"Key": "role", "Value": "gateway"},
                      {"Key": "dstack_project", "Value": project_id},
                  ],
              },
          ],
      )
      group_id = security_group["GroupId"]
  
      ec2_client.authorize_security_group_ingress(
          GroupId=group_id,
          IpPermissions=[
              {
                  "FromPort": 0,
                  "ToPort": 65535,
                  "IpProtocol": "tcp",
                  "IpRanges": [{"CidrIp": "0.0.0.0/0"}],
              }
          ],
      )
  
      ec2_client.authorize_security_group_egress(
          GroupId=group_id,
          IpPermissions=[{"IpProtocol": "-1"}],
      )
      return group_id
  
file_path: dstack/src/dstack/_internal/core/backends/aws/resources.py
imports: import json
  from typing import Any, Dict, List, Optional
  import botocore.client
  import botocore.exceptions
  import dstack.version
  from dstack._internal.core.errors import ResourceNotFoundError
label_desc: Use image node_id 7 for calling a global function with example usage: create_gateway_security_group(ec2_client, project_id) and returns: group_id, response