首页 > 解决方案 > AWS Cloudformation:为未命名的 ECS 服务输出 ServiceName

问题描述

我通过 cloudformation 创建 ECS 堆栈。一切正常。由于某种原因,我没有在定义中为ECS服务(名称:服务)指定ServiceName。但是,我想在 Cloudformation 创建堆栈后将其输出。所以为了这个目的,我定义了这样的输出:

Outputs:
  ECSServiceName:
    Description: Service Name I want to see
    Value: !GetAtt Service.ServiceName

当我运行更新 CF Stack 时,我收到来自 AWS 的错误:

Requested attribute ServiceName must be a readonly property in schema for AWS::ECS::Service

如果之前没有严格指定,这是否意味着我无法在输出中接收它?或者我在输出定义的某个地方犯了一个错误?

标签: amazon-web-servicesamazon-cloudformationdevopsamazon-ecsaws-fargate

解决方案


您必须从模板中导出。 ECSServiceName获取 ECS 服务名称的正确方法是!GetAtt Service.Name


Outputs:
  ECSServiceName:
    Description: Service Name I want to see
    Value: !GetAtt Service.Name
    Export:
      Name: ECSServiceName

然后,在其他模板中,您可以使用ImportValue来引用导出的输出:

!ImportValue ECSClusterName

推荐阅读