首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWS Cloudformation容器覆盖

AWS Cloudformation容器覆盖
EN

Stack Overflow用户
提问于 2018-06-26 10:07:36
回答 2查看 1.4K关注 0票数 4

我使用cloudformation创建了taskDefinition,并在ContainerDefinitions中让Commanddaily作为参数运行应用程序。

代码语言:javascript
复制
TaskDefinition: 
  Type: AWS::ECS::TaskDefinition
  Properties:
    :
    :
    ContainerDefinitions:
    - Name: test-report
      :
      :
      Command:
      - "./test_report"
      - daily

我想要创建不同频率的TaskSchedule (例如,每日、每周、每月等)。

我知道在亚马逊网络服务控制台中,我可以转到Edit Scheduled Task > Schedule Targets > Container override并使用./test_report, weekly更新command override

但是如何覆盖cloudformation中的命令呢?这是在Targets属性中做的事情吗??

代码语言:javascript
复制
  TaskSchedule:
    Type: AWS::Events::Rule
    Properties:
      :
      Targets:

提前感谢

EN

回答 2

Stack Overflow用户

发布于 2019-09-13 12:24:13

@toske的答案现在已经过期了。您可以使用目标的Input参数设置容器覆盖。例如:

代码语言:javascript
复制
  LogicalResource:
    Type: AWS::Events::Rule
    Properties:
      Description: "a scheduled task"
      Name: my_scheduled_task
      ScheduleExpression: "cron(* * * * ? *)"
      State: ENABLED
      RoleArn: !GetAtt MyRole.Arn
      Targets:
        - Id: fargate
          Arn: !GetAtt MyCluster.Arn
          RoleArn: !GetAtt MyTaskRole.Arn
          Input: '{ "containerOverrides": [{"name": "container", "command": [ "python", "manage.py", "my_awesome_management_command", "-a" ]}]}'
          EcsParameters:
             ....
票数 6
EN

Stack Overflow用户

发布于 2018-06-26 11:07:11

在cloudformation模板中,使用cron表达式(或者CloudWatch表达式)定义cron事件规则时间表。您不能从规则本身覆盖入口点,但可以为每种报告类型(频率)创建任务定义。我在UI或cloudformation文档中找不到任务命令覆盖。

代码语言:javascript
复制
TaskDefinitionDaily: 
  Type: AWS::ECS::TaskDefinition
  Properties:
     # other task definition elements here
     ContainerDefinitions:
       # other container definitions here
        Command: 
          - "./test_report"
          - daily

TaskDefinitionWeekly: 
  Type: AWS::ECS::TaskDefinition
  Properties:
     # other task definition elements here
     ContainerDefinitions:
       # other container definitions here
        Command: 
          - "./test_report"
          - weekly

TaskDefinitionMonthly: 
  Type: AWS::ECS::TaskDefinition
  Properties:
     # other task definition elements here
     ContainerDefinitions:
       # other container definitions here
        Command: 
          - "./test_report"
          - monthly


# daily schedule at midnight UTC      
ScheduledRuleDaily: 
  Type: "AWS::Events::Rule"
  Properties: 
    Description: "ScheduledRule"
    ScheduleExpression: "cron(00 00 * * ? *)"
    State: "ENABLED"
    Targets:
          - Arn: !GetAtt 
              - MyCluster
              - Arn
            RoleArn: !GetAtt 
              - ECSTaskRole
              - Arn
            Id: id1
            EcsParameters:
              TaskCount: 1
              TaskDefinitionArn: !Ref TaskDefinitionDaily


# weekly schedule at midnight UTC   
ScheduledRuleWeekly: 
  Type: "AWS::Events::Rule"
  Properties: 
    Description: "ScheduledRule"
    ScheduleExpression: "cron(00 00 ? * 1 *)"
    State: "ENABLED"
    Targets:
          - Arn: !GetAtt 
              - MyCluster
              - Arn
            RoleArn: !GetAtt 
              - ECSTaskRole
              - Arn
            Id: id1
            EcsParameters:
              TaskCount: 1
              TaskDefinitionArn: !Ref TaskDefinitionWeekly

# monthly schedule  at midnight UTC     
ScheduledRuleMonthly: 
  Type: "AWS::Events::Rule"
  Properties: 
    Description: "ScheduledRule"
    ScheduleExpression: "cron(00 00 1 * ? *)"
    State: "ENABLED"
    Targets:
          - Arn: !GetAtt 
              - MyCluster
              - Arn
            RoleArn: !GetAtt 
              - ECSTaskRole
              - Arn
            Id: id1
            EcsParameters:
              TaskCount: 1
              TaskDefinitionArn: !Ref TaskDefinitionMonthly

您可以在amazon documentation website上阅读有关事件规则表达式的更多信息。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51033944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档