[英]AWS ECS: Invalid service in ARN (Service: AmazonECS; ...)
嘗試使用 cloudformation 創建 ECS 服務(在 Fargate 上)但出現錯誤:
ARN 中的服務無效(服務:AmazonECS;狀態代碼:400;錯誤代碼:InvalidParameterException;請求 ID:xxx)。
根據錯誤消息,似乎某些 ARN 是錯誤的,但我沒有找到原因,我檢查了 IAM 角色的 ARN 並沒有問題。 其他 ARN 與 !Ref function 一起傳遞(因此不是拼寫錯誤)
所有資源(包括來自所有其他嵌套模板、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,包括Cluster
、 TaskDefinition
和TargetGroup
。 當這些參數之一錯誤時會發生錯誤。 請仔細檢查這些參數並確保它們是有效的 ARN。
我有完全相同的錯誤,在我的情況下,我犯了一個錯誤並提供了錯誤的Cluster
值。
我在這里發布了一個答案,因為這是此錯誤消息的第一個搜索結果,並且沒有答案。
我的問題是默認的 AWS 區域設置錯誤。 要解決此問題,請運行以下命令(使用正確的區域)。
$ aws configure set default.region us-west-2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.