gpt4 book ai didi

amazon-web-services - AWS CloudFormation 服务无法放置任务,因为没有容器实例满足其所有要求

转载 作者:行者123 更新时间:2023-12-03 07:46:56 26 4
gpt4 key购买 nike

我正在尝试使用 ci/cd 管道创建 ECS。我已经定义了 TaskDefination 和 ECSService 以及 VPC。

cloudformation 创建了集群,但在创建 ECSService 时卡住了。

我参加了 ECSService 事件,发现错误“服务 my-service-name 无法放置任务,因为没有容器实例满足其所有要求”。原因:您的集群中未找到容器实例。有关详细信息,请参阅“故障排除”部分。'

enter image description here

我的管道中是否缺少某些内容?

这是我的 TaskDefination 和 ECSService

AWSTemplateFormatVersion: 2010-09-09
Description: The CloudFormation template for the Fargate ECS Cluster.

Parameters:
Stage:
Type: String
ContainerPort:
Type: Number
ImageURI:
Type: String

Resources:

# Create an ECS Cluster
Cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 'Cluster']]

# Create a VPC
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: True
EnableDnsSupport: True

# Create a Subnet
SubnetA:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.0.0/24
VpcId: !Ref VPC
AvailabilityZone: !Join ['', [!Ref "AWS::Region", 'a']]

# Create a Subnet
SubnetB:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.1.0/24
VpcId: !Ref VPC
AvailabilityZone: !Join ['', [!Ref "AWS::Region", 'b']]

# Create Access Role for ECS-Tasks
ExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 'ExecutionRole']]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'

# Create a TaskDefinition with container details
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
NetworkMode: awsvpc
RequiresCompatibilities:
- 'EC2'
TaskRoleArn: !Ref ExecutionRole
ExecutionRoleArn: !Ref ExecutionRole
ContainerDefinitions:
- Name: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 'Container']]
Image: !Ref ImageURI
Cpu: 1024
Memory: 1024
PortMappings:
- ContainerPort: !Ref ContainerPort
HostPort: !Ref ContainerPort

# Create an ECS Service and add created Cluster, TaskDefintion, Subnets, TargetGroup and SecurityGroup
ECSService:
Type: AWS::ECS::Service
Properties:
ServiceName: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 'ECSService']]
Cluster: !Ref Cluster
TaskDefinition: !Ref TaskDefinition
DesiredCount: 1
LaunchType: EC2
NetworkConfiguration:
AwsvpcConfiguration:
Subnets:
- !Ref SubnetA
- !Ref SubnetB

我已尝试回答已发布的问题。在大多数情况下,人们会在 AWS Web 界面上收到此错误。对我来说 ECS 正在使用 Web 界面工作。我无法使用我的管道让它工作。

最佳答案

您必须明确配置EC2 container instances用于您的 ECS 任务。您当前的 TF 代码不会创建任何 ECS 集群和任务使用的 EC2 实例。

关于amazon-web-services - AWS CloudFormation 服务无法放置任务,因为没有容器实例满足其所有要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73930022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com