gpt4 book ai didi

amazon-web-services - AWS ECS : Invalid service in ARN (Service: AmazonECS; . ..)

转载 作者:行者123 更新时间:2023-12-03 07:11:29 32 4
gpt4 key购买 nike

尝试使用 cloudformation 创建 ECS 服务(在 Fargate 上)但出现错误:

Invalid service in ARN (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: xxx).

根据错误信息,似乎有些ARN是错误的,但我没有找到原因,我检查了IAM角色的ARN,没有问题。其他 ARN 通过 !Ref 函数传递(因此不是拼写错误)

所有资源(包括来自所有其他嵌套模板、vpc、集群、alb 等)均已创建,“服务”资源(ECS 服务)除外。

下面是使用的模板(嵌套模板)。所有参数都可以(从根模板传递)。参数 TaskExecutionRole 和 ServiceRole 是来自 ECS 向导创建的 IAM 角色的 ARN:

Description: >
Deploys xxx ECS service, with load balancer listener rule,
target group, task definition, service definition and auto scaling

Parameters:
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
EnvironmentType:
Description: See master template
Type: String
VpcId:
Type: String
PublicSubnet1:
Type: String
PublicSubnet2:
Type: String
ALBListener:
Description: ALB listener
Type: String
Cluster:
Description: ECS Cluster
Type: String
TaskExecutionRole:
Description: See master template
Type: String
ServiceRole:
Description: See master template
Type: String
ServiceName:
Description: Service name (used as a variable)
Type: String
Default: xxx
Cpu:
Description: Task size (CPU)
Type: String
Memory:
Description: Task size (memory)
Type: String

Conditions:
HasHttps: !Equals [!Ref EnvironmentType, production]
HasNotHttps: !Not [!Equals [!Ref EnvironmentType, production]]

Resources:
ServiceTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: !Sub '${EnvironmentName}-${ServiceName}'
VpcId: !Ref VpcId
TargetType: ip
Port: 80
Protocol: HTTP

AlbListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref ServiceTargetGroup
Conditions:
- Field: host-header
Values: [www.mydomain.com] # test
ListenerArn: !Ref ALBListener
Priority: 1

TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub '${EnvironmentName}-${ServiceName}-Task'
ContainerDefinitions:
- Name: !Ref ServiceName
Image: nginx
PortMappings:
- ContainerPort: 80
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref EnvironmentName
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: !Ref ServiceName
NetworkMode: awsvpc
RequiresCompatibilities: [FARGATE]
Cpu: !Ref Cpu
Memory: !Ref Memory
ExecutionRoleArn: !Ref TaskExecutionRole

Service:
Type: AWS::ECS::Service
DependsOn: TaskDefinition
Properties:
Cluster: !Ref Cluster
ServiceName: !Ref ServiceName
TaskDefinition: !Ref TaskDefinition
LaunchType: FARGATE
DesiredCount: 1
LoadBalancers:
- ContainerName: !Ref ServiceName
ContainerPort: 80
TargetGroupArn: !Ref ServiceTargetGroup
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets:
- !Ref PublicSubnet1
- !Ref PublicSubnet2
Role: !Ref ServiceRole

我在这件事上浪费了几个小时,但无法解决它,我在文档中查阅了很多内容,但什么也没有,如果有人知道如何提供帮助的话。

谢谢!

最佳答案

错误消息令人困惑,因为它没有解释哪个参数是错误的。 Amazon API 需要多个参数中的资源 ARN,包括 ClusterTaskDefinitionTargetGroup。当这些参数之一错误时,就会发生错误。请仔细检查这些参数并确保它们是有效的 ARN。

我遇到了完全相同的错误,就我而言,我犯了一个错误并提供了错误的Cluster值。

我在这里发布一个答案,因为这是此错误消息的第一个搜索结果,但没有答案。

关于amazon-web-services - AWS ECS : Invalid service in ARN (Service: AmazonECS; . ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55253585/

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