我正在尝试将临时卷附加到我们在 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/