CloudFormation ECS TaskDefinition: correct type/processing for Parameter for EntryPoint in YAML Template

0

I want to be able to accept an optional Parameter for the EntryPoint of a AWS::ECS::TaskDefinition -> ContainerDefinitions[], in a YAML CloudFormation template. This is a little tricky, since ECS wants a comma-separated list for this, e.g. /bin/bash,-c,echo hello, but in the CloudFormation template, it appears to be an array of string.

What is the best type to define for a EntryPoint Parameter in this case? The error I'm currently trying to avoid is:

Resource handler returned message: "Model validation failed (#/ContainerDefinitions/0/EntryPoint/0: expected type: String, found: JSONArray 

I've defined the parameter currently as: CommaDelimitedList:

  EntryPoint:
    Type: CommaDelimitedList
    Description: "Task entrypoint (Optional - image default is script /start)"

... which is yielding a JSONArray?, but I think I need an array of strings, which I'm not getting from:

      ContainerDefinitions:      
          EntryPoint:
            - !If
              - EntryPointProvided
              - !Ref EntryPoint
              - !Ref 'AWS::NoValue'

What is the best type to use and the most direct processing to get to the type required in the template and by ECS? Or a current fix for the JSONArray would be fine. Thanks!

asked 2 years ago2471 views
1 Answer
1
Accepted Answer

I believe you want to try something like below to avoid the error you are seeing. This will treat the result of the If function as the input for the EntryPoint property as opposed to an list of strings within a outer list.

Note that the ‘-‘ preceding the if function has been removed.

      ContainerDefinitions:      
          EntryPoint: !If
              - EntryPointProvided
              - !Ref EntryPoint
              - !Ref 'AWS::NoValue'
answered 2 years ago
  • Spot on, perfect answer thanks Shane - clearly I missed that I was wrapping the dereference with that extra -. With this fix I am now able to pass arrays via comma-separated strings for both EntryPoint and Command via template parameters, which is awesome.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions