TaskDefinition-遇到不受支持的属性名称-环境

时间:2018-07-18 22:39:13

标签: amazon-web-services amazon-cloudformation amazon-ecs aws-fargate

运行声明了一些环境变量的CloudFormation脚本时,CloudFormation会引发以下错误:

CREATE_FAILED   AWS::ECS::TaskDefinition    ECSTaskDefinition   Encountered unsupported property Name

与CloudFormation模板中的以下资源有关

"ECSTaskDefinition": {
    "Type": "AWS::ECS::TaskDefinition",
    "Properties": {
        "Cpu": "256",
        "ExecutionRoleArn": {
            "Fn::GetAtt": [
                "ECSTaskRole",
                "Arn"
            ]
        },
        "Family": {
            "Ref": "AWS::StackName"
        },
        "Memory": "500",
        "NetworkMode": "awsvpc",
        "RequiresCompatibilities": [
            "FARGATE"
        ],
        "ContainerDefinitions": [
            {
                "Environment": [
                    {
                        "Name": "cloudsearch:search_endpoint",
                        "Value": {
                            "Ref": "CloudSearchDomainServiceUrl"
                        }
                    }
                ],
                "Essential": true,
                "Image": {
                    "Ref": "ContainerImage"
                }
            }
        ]
    }
}

我不确定上述内容有什么问题,因为从文档中可以正确地声明环境块-https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions-environment.html

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

想知道问题是否出在环境变量cloudsearch:search_endpoint的实际名称上,通常我们遵循bash变量约定来创建环境变量,请尝试类似CLOUDSEARCH_SEARCH_ENDPOINT

答案 1 :(得分:0)

我也面临着同样的问题,还没有找到解决方案。 让我知道是否有人可以得到答案。

我将名称用作ELB,将值用作temp,这与常见的命名和问题无关。

答案 2 :(得分:0)

 ECSAppTask:
    Type: AWS::ECS::TaskDefinition
    Properties:
        RequiresCompatibilities: 
          - !FindInMap
            - ECSEnvironmentDetails
            - !Ref EnvironmentTier
            - Compatibilities
        ContainerDefinitions:
            - 
                Name: !Join ['-', [!Ref 'ECSCluster', app]]
                Image: !FindInMap
                        - ECSEnvironmentDetails
                        - !Ref EnvironmentTier
                        - AppImage
                Memory: 1024
                Cpu: 0
                Essential: true
                PortMappings:
                    - ContainerPort: 80
                      HostPort: 80
                    - ContainerPort: 8080
                      HostPort: 8080
                Environment:
                    - Name: CONFIGURE_MODE
                      Value: config_mode
                    - Name: ENVIRONMENT
                      Value: env
                    - Name: ENVTYPE
                      Value: env_type
                    - Name: LICENSE
                      Value: accept
                LogConfiguration:
                  LogDriver: logs
                  Options:
                      awslogs-group: !Ref ECSAppLogGroup
                      awslogs-region: !FindInMap
                                      - ECSEnvironmentDetails
                                      - !Ref EnvironmentTier
                                      - LogsRegion
                      awslogs-stream-prefix: !FindInMap
                                              - ECSEnvironmentDetails
                                              - !Ref EnvironmentTier
                                              - LogsStreamPrefix
                MountPoints:
                    - 
                      ContainerPath: /default/logs
                      SourceVolume:  !FindInMap
                                        - ECSEnvironmentDetails
                                        - !Ref EnvironmentTier
                                        - AppVolumeName
        Volumes:
            - 
              Host:
                SourcePath: !FindInMap
                                 - ECSEnvironmentDetails
                                 - !Ref EnvironmentTier
                                 - AppVolumeSourcePath
              Name: !FindInMap
                       - ECSEnvironmentDetails
                       - !Ref EnvironmentTier
                       - AppVolumeName 

这是我的yaml文件,用于定义taskdefinition,并且可以正常工作。一开始我遇到了同样的问题“ TaskDefinition-遇到不受支持的属性名称-Environment”,然后我意识到我在环境键值列表中使用了所有小写字母, 所以我从以下位置更改了Yaml中的环境:

       Environment:
                    - name: CONFIGURE_MODE
                      value: config_mode
                    - name: ENVIRONMENT
                      value: env
                    - name: ENVTYPE
                      value: env_type
                    - name: LICENSE
                      value: accept

            Environment:
                    - Name: CONFIGURE_MODE
                      Value: config_mode
                    - Name: ENVIRONMENT
                      Value: env
                    - Name: ENVTYPE
                      Value: env_type
                    - Name: LICENSE
                      Value: accept

并尝试更新或重新创建堆栈,两者均成功完成。