使用 CloudFormation 将临时存储附加到 Fargate 服务 - 预期类型:JSONArray,找到:JSONObject

Attach ephemeral storage to Fargate service with CloudFormation - expected type: JSONArray, found: JSONObject

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

但是,在放置音量参数时,它失败并出现此错误:

Model validation failed (#/Volumes: expected type: JSONArray, found: JSONObject #/ContainerDefinitions/0/MountPoints: expected type: JSONArray, found: JSONObject #/ContainerDefinitions/0/PortMappings/0/ContainerPort: expected type: Number, found: String)

这是模板:

  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。

有人能告诉我正确的方向吗?

干杯!

MountPoints should be a list of MountPoint。因此在你的情况下它应该是(注意-):

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

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

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