AWS ECS Exec: 无法在Fargate上开始shell
创始人
2024-11-15 17:00:12
0

要在AWS Fargate上启动shell,可以使用AWS Systems Manager Session Manager。以下是一个解决方法,包含了使用Session Manager启动shell的代码示例。

  1. 确保已安装AWS CLI,并使用正确的访问密钥和区域配置。

  2. 使用以下命令创建一个IAM角色,以便在Fargate任务上使用Session Manager。

aws iam create-role \
    --role-name ecs-fargate-session-role \
    --assume-role-policy-document '{
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": {
                    "Service": "ecs-tasks.amazonaws.com"
                },
                "Action": "sts:AssumeRole"
            }
        ]
    }'
  1. 授予该角色适当的权限,使其能够使用Session Manager。以下是一个示例策略,允许角色具有必需的权限。
aws iam put-role-policy \
    --role-name ecs-fargate-session-role \
    --policy-name ecs-fargate-session-role-policy \
    --policy-document '{
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "ssmmessages:CreateControlChannel",
                    "ssmmessages:CreateDataChannel",
                    "ssmmessages:OpenControlChannel",
                    "ssmmessages:OpenDataChannel"
                ],
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "ssm:UpdateInstanceInformation",
                    "ssmmessages:CreateControlChannel",
                    "ssmmessages:CreateDataChannel",
                    "ssmmessages:OpenControlChannel",
                    "ssmmessages:OpenDataChannel",
                    "ssm:UpdateInstanceInformation",
                    "ssm:GetConnectionStatus",
                    "ssm:DescribeInstanceProperties",
                    "ssm:GetManifest",
                    "ssm:GetDocument",
                    "ssm:ListInstanceAssociations",
                    "ssm:ListAssociations",
                    "ssm:UpdateAssociationStatus",
                    "ssm:UpdateInstanceAssociationStatus",
                    "ssm:DescribeAssociation",
                    "ssm:DescribeInstanceAssociationStatus",
                    "ssm:GetDeployablePatchSnapshotForInstance",
                    "ssm:DescribeDocument",
                    "ssm:ListCommandInvocations",
                    "ssm:ListCommands",
                    "ssm:GetCommandInvocation",
                    "ssm:GetCommandOutput",
                    "ssm:CancelCommand",
                    "ssm:ListDocumentVersions",
                    "ssm:CreateAssociation",
                    "ssm:CreateAssociationBatch",
                    "ssm:DeleteAssociation",
                    "ssm:UpdateAssociationStatus",
                    "ssm:UpdateInstanceAssociationStatus",
                    "ssm:LabelParameterVersion",
                    "ssm:GetParameterHistory",
                    "ssm:GetParametersByPath",
                    "ssm:GetParameters",
                    "ssm:GetParameter",
                    "ssm:PutParameter",
                    "ssm:DeleteParameter",
                    "ssm:DescribeParameters",
                    "ssm:GetDeployablePatchSnapshotForInstance",
                    "ec2messages:AcknowledgeMessage",
                    "ec2messages:DeleteMessage",
                    "ec2messages:FailMessage",
                    "ec2messages:GetEndpoint",
                    "ec2messages:GetMessages",
                    "ec2messages:SendReply",
                    "ssm:UpdateInstanceInformation"
                ],
                "Resource": "*"
            }
        ]
    }'
  1. 创建一个Fargate任务定义文件,指定上述创建的IAM角色。以下示例文件是以JSON格式写的,可以根据需要进行调整。
{
    "family": "my-task-family",
    "networkMode": "awsvpc",
    "executionRoleArn": "ecs-fargate-session-role-ARN",
    "containerDefinitions": [
        {
            "name": "my-container",
            "image": "my-container-image",
            "command": [
                "sh",
                "-c",
                "sleep 1000"
            ],
            "essential": true
        }
    ],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "256",
    "memory": "512"
}

确保将"ecs-fargate-session-role-ARN"替换为先前创建的IAM角色的ARN,并在"my-container-image"中指定您自己的容器镜像。

  1. 使用以下

相关内容

热门资讯

交流学习经验!微扑克苹果版(w... 交流学习经验!微扑克苹果版(wePOke)外挂透明挂辅助工具(辅助挂)科技教程(有挂解惑)-哔哩哔哩...
一分钟教你(cloudpoke... 您好,cloudpoker外挂这款游戏可以开挂的,确实是有挂的,需要了解加微【285696317】很...
记者揭秘!德扑助手(WEpok... 记者揭秘!德扑助手(WEpoke)外挂透明挂辅助机制(透视)曝光教程(有挂神器)-哔哩哔哩;德扑助手...
透视透明(Wepoke控制)外... 大家肯定在之前Wepoke控制或者Wepoke控制中玩过透视透明(Wepoke控制)外挂透明挂辅助软...
查到实测(德州ai软件)外挂透... 查到实测(德州ai软件)外挂透明挂辅助机制(辅助挂)软件透明挂(发现有挂)-哔哩哔哩;原来确实真的有...
免费测试版!Wepoke挂(w... WePoker透视辅助工具核心要点解析‌,免费测试版!Wepoke挂(wEpoke)外挂透明挂辅助工...
热点讨论(poker mast... 热点讨论(poker master安卓版)外挂透明挂辅助app(辅助挂)辅助透视(有挂工具)-哔哩哔...
技术分享(WPK开挂)外挂透明... 技术分享(WPK开挂)外挂透明挂辅助器(辅助挂)竟然是真的有挂(2023已更新)(哔哩哔哩)准备好在...
必知教程(Wepoke新版)外... 必知教程(Wepoke新版)外挂透明挂辅助APP(辅助挂)软件透明挂(有挂头条)-哔哩哔哩;Wepo...
1分钟了解!wepoke辅助(... wepoke辅助新手教程相关信息汇总(需添加指定薇757446909获取下载链接);1分钟了解!we...