首页 > 解决方案 > AWS 更改 ECS 服务任务定义(部署)而不使用 CloudFormation

问题描述

慢慢地将我们所有的资源转移到由 CloudFormation 管理,到目前为止,这相对轻松。

在 ECS 服务上部署新任务定义(仅限暂存环境)时,我遇到了一些困难。由于 ECS 服务引用了一个参数,我认为有些部分无法使用 CloudFormation 进行管理。

目前的流程:

这一切都很好!


将 ECS 资源管理移至 CloudFormation,类似于

Parameters:
  TaskDefinition:
    Type: String
    Description: Task Definition ARN

Resources:
  HTTPService:
    Type: AWS::ECS::Service
    DependsOn: ListenerRule
    Properties:
      Cluster: !Ref ECSCluster
    Role: !Ref ServiceRole
    DesiredCount: 1
    HealthCheckGracePeriodSeconds: 120
    TaskDefinition: !Ref TaskDefinition
    LoadBalancers:
      - ContainerName: http
        ContainerPort: 80
        TargetGroupArn: !Ref TargetGroup

TargetGroup:
  Type: AWS::ElasticLoadBalancingV2::TargetGroup
  Properties:
    VpcId: !Ref VPC
    Port: 80
    Protocol: HTTP
    Matcher:
      HttpCode: 200
    HealthCheckIntervalSeconds: 15
    HealthCheckPath: /
    HealthCheckProtocol: HTTP
    HealthCheckTimeoutSeconds: 5
    HealthyThresholdCount: 2

ListenerRule:
  Type: AWS::ElasticLoadBalancingV2::ListenerRule
  Properties:
    ListenerArn: !Ref Listener
    Priority: 2
    Conditions:
      - Field: path-pattern
        Values:
          - /blog
    Actions:
      - TargetGroupArn: !Ref TargetGroup
        Type: forward

如果我现在手动运行aws ecs update-service命令,CloudFormation 堆栈将与 ECS 服务不同步。

研究了一下可能会运行一个aws cloudformation update-stack,但 BitBucket 用户的 IAM 权限变得非常复杂。

也许我在这里错误地设置了这一切。这里有任何指示/建议吗?

标签: amazon-web-servicesamazon-cloudformation

解决方案


推荐阅读