【问题标题】:Attach ephemeral storage to Fargate service with CloudFormation - expected type: JSONArray, found: JSONObject使用 CloudFormation 将临时存储附加到 Fargate 服务 - 预期类型:JSONArray,找到:JSONObject
【发布时间】:2021-01-16 00:19:56
【问题描述】:

我正在尝试将临时卷附加到我们在 Fargate 上运行的服务,以便它可以在将文件复制到 S3 之前生成一些文件。当我在没有卷信息的情况下启动服务时,CloudFormation 模板创建成功,服务运行。

但是,当放置音量参数时,它会失败并出现以下错误:

模型验证失败(#/Volumes:预期类型:JSONArray,找到:JSONObject #/ContainerDefinitions/0/MountPoints:预期类型:JSONArray,找到:JSONObject #/ContainerDefinitions/0/PortMappings/0/ContainerPort:预期类型:编号,找到:字符串)

这是模板:

  Cluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: !Join ['-', [!Ref Env, !Ref ShortServiceName, cluster]]
  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    DependsOn: LogGroup
    Properties:
      Family: !Join ['-', [!Ref Env, !Ref ShortServiceName, 'taskdefinition']]
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      Cpu: !Ref Cpu
      Memory: !Ref Memory
      Volumes:
        Name: !Ref VolumeName
        DockerVolumeConfiguration:
          Autoprovision: True
          Scope: Task
      ExecutionRoleArn: !Ref ExecutionRole
      TaskRoleArn: !Ref TaskRole
      ContainerDefinitions:
        - Name: !Join ['-', [!Ref Env, !Ref ShortServiceName]]
          Image: !Ref Image
          RepositoryCredentials:
            CredentialsParameter: !Ref RepositoryCredentials
          PortMappings:
            - ContainerPort: !Ref ContainerPort
          MountPoints:
            ContainerPath: "/app"
            SourceVolume: !Ref VolumeName
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-region: !Ref AWS::Region
              awslogs-group: !Ref LogGroup
              awslogs-stream-prefix: ecs

  ContainerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      Tags:
        -
          Key: Name
          Value: !Join ['-', [!Ref ShortServiceName, 'app-sg']]
      GroupDescription: !Join ['-', [!Ref ShortServiceName, ContainerSecurityGroup]]
      VpcId: !Ref VPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: !Ref ContainerPort
          ToPort: !Ref ContainerPort
          SourceSecurityGroupId: !Ref ManagementSecurityGroup

  Service:
    Type: AWS::ECS::Service
    Properties:
      ServiceName: !Ref ServiceName
      Cluster: !Ref Cluster
      TaskDefinition: !Ref TaskDefinition
      DeploymentConfiguration:
        MinimumHealthyPercent: 50
        MaximumPercent: 200
      DesiredCount: !Ref DesiredCount
      LaunchType: FARGATE
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: DISABLED
          Subnets:
            - !Ref AppSubnetA
            - !Ref AppSubnetB
          SecurityGroups:
            - !Ref ManagementSecurityGroup
            - !Ref ContainerSecurityGroup

  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Join ['/', [/ecs, !Ref Env, !Ref ServiceName]]

Outputs:
  ContainerSecurityGroup:
    Description: ContainerSecurityGroup
    Value: !Ref ContainerSecurityGroup

我已经搜索了该问题的高位和低位,但没有找到与该问题相关的任何内容。此外,ContainerPort 参数在不附加卷时可以作为字符串正常工作。我也尝试将类型从 String 更改为 Number,但仍然得到相同的 JsonObject,而它期待 JsonArray。

有人能把我引向正确的方向吗?

干杯!

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation docker-volume aws-fargate


    【解决方案1】:

    MountPoints 应该是MountPoint 的列表。因此在你的情况下应该是(注意-):

              MountPoints:
                - ContainerPath: "/app"
                  SourceVolume: !Ref VolumeName
    

    【讨论】:

    • 谢谢!但我不断收到:模型验证失败(#/Volumes:预期类型:JSONArray,找到:JSONObject #/ContainerDefinitions/0/PortMappings/0/ContainerPort:预期类型:数字,找到:String)
    • 在你的问题中你没有!Ref ContainerPort的定义,所以我不能评论它。可能您使用的是字符串,而不是数字。
    • 我有字符串,然后改成数字,然后又改回字符串。失败并出现同样的错误:(不过,感谢您的提示,我一直更加关注破折号,现在在模板中找到了所有内容,错误已经消失。将您的答案视为有效,非常感谢!!
    • @Karasu-O-Matic 谢谢。很高兴它成功了。如果答案有帮助,将不胜感激。必须点击 upvote/downvoate 按钮下的“勾号”。
    【解决方案2】:

    把它作为一个完整的 JSON 对象,没有引号!。示例

    MyRepo:
      Type: AWS::ECR::Repository
      Properties:
        RepositoryName: my/repo
        EncryptionConfiguration: {"encryptionType": "AES256"}
      DeletionPolicy: Retain
    

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 1970-01-01
      • 2021-05-19
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多