amazon-web-services - AWS 更改 ECS 服务任务定义(部署)而不使用 CloudFormation
问题描述
慢慢地将我们所有的资源转移到由 CloudFormation 管理,到目前为止,这相对轻松。
在 ECS 服务上部署新任务定义(仅限暂存环境)时,我遇到了一些困难。由于 ECS 服务引用了一个参数,我认为有些部分无法使用 CloudFormation 进行管理。
目前的流程:
推送到
develop
BitBucket 上的分支BitBucket Pipelines 然后处理(简化):
创建带有标签的 ECR 图像
latest
通过创建新的任务定义修订
aws ecs register-task-definition --cli-input-json $TASK_JSON
使用新的任务定义更新 ECS 服务
aws ecs update-service --cluster ${ECS_CLUSTER_NAME} --service ${ECS_SERVICE} --task-definition $TASK_DEFINITION
这一切都很好!
将 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 权限变得非常复杂。
也许我在这里错误地设置了这一切。这里有任何指示/建议吗?
解决方案
推荐阅读
- python - QPlainTextEdit 和 QCompleter 焦点问题
- javascript - 创建一个firebase函数以在数据库中设置负服务器时间戳但保留NaN
- sql - 为 RDLC 报告创建视图的 SQL 查询
- powershell - 是否可以使用 powershell 甚至 cmd 使用密码/哈希加密任何文件?
- dialogflow-es - Dialogflow 上下文和实体
- python - 如何降级numpy?
- php - 只有使用 MySQL 才能实现这一点
- javascript - ReactJS 必须将组件传递给 connect 返回的函数
- vuejs2 - Element UI - 自定义标签表单选择组件
- symfony - 无需调用控制器方法即可测试电子邮件发送功能