1

运行声明一些环境变量的 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"
                }
            }
        ]
    }
}

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

任何帮助将非常感激。

4

2 回答 2

1

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

于 2018-07-19T00:55:02.760 回答
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 

这是我定义 taskdefinition 的 yaml 文件,它可以工作。一开始我遇到了同样的问题“TaskDefinition - 遇到不支持的属性名称 - 环境”,然后我意识到我在环境键值列表中使用了所有小写字母,所以我在 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

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

于 2018-11-06T19:43:31.300 回答