1
votes

When running a CloudFormation Script that declares some environment variables the following error is raised with CloudFormation:

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

Which relates to the following resource within the CloudFormation template

"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"
                }
            }
        ]
    }
}

I'm not sure what's wrong with the above as from the documentation the Environment block is declared correctly -https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions-environment.html

Any help would be much appreciated.

2

2 Answers

1
votes

Wondering if the issue is with the actual name of the env variable cloudsearch:search_endpoint usually we follow bash variable convention for creating environmental variables, try something like CLOUDSEARCH_SEARCH_ENDPOINT

0
votes
 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 

This is my yaml file to define taskdefinition and it works. I had the same problem "TaskDefinition - Encountered unsupported property Name - Environment" at the beginning, then I realized that I am using all lower cases in environment key value list, so I changed environment in yaml from:

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

to

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

and tried to update or recreate the stack, both are completed successfully.