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

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

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

但是,当输入卷参数时,它会失败并出现以下错误:

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应该是 MountPoint 的列表。因此,在您的情况下,它应该是(注意 -):

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

关于amazon-web-services - 使用 CloudFormation 将临时存储附加到 Fargate 服务 - 找到预期类型 : JSONArray,:JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64135684/

相关文章:

docker 撰写 v3 : sharing bind-mounted volume between multiple containers with top-level volumes syntax

ruby-on-rails - 使用 AWS Elastic Beanstalk 和 Ruby 容器设置私有(private) Github 访问

oracle - 数据库从 Oracle RAC 迁移到 AWS Amazon Aurora

docker - 使用 CloudFormation 运行 Ec2 中存在的 docker-compose

docker - Docker 容器如何写入具有通过组成员资格授予的权限的挂载目录?

Docker-compose 卷不保存 Keycloak 的容器状态

java - 读取S3对象并写入InMemory Buffer

git - AWS-Ubuntu-Git 安装错误致命 : $HOME not set

amazon-web-services - 如何使用同一 aws 账户中的堆栈集将所有资源部署到另一个区域?

python - 如何为我的 Lambda 函数创建可重复使用的 CloudFormation 模板?