4

The scope of the question:

AWS CodeBuild, ParametersOverrides section

Using Parameter Override Functions with CodePipeline Pipelines

1) I can pass a string to ParameterOverrides, and then pass them to a nested stack, as it is described below

-create a string parameter

-pass it to ParameterOverrides section of the AWS CodeBuild project

-parse parameter in the nested stack

Quoting the official documentation: AWS::CloudFormation::Stack

If you use the Ref function to pass a parameter value to a nested stack, comma-delimited list parameters must be of type String. In other words, you cannot pass values that are of type CommaDelimitedList to nested stacks.

2) I can not figure out on how to transform a List to a string inside a ParameterOverrides section with the configuration below:

-define a Parameter with type of list ServiceSubnets: Type: List Description: Subnets associated with the service

-try to pass a parameter inside ParameterOverrides section as a value to a nested stack, apply Join function to transform it to a string

           ParameterOverrides: !Sub |
              {
                "ImageURI" : { "Fn::GetParam" : [ "BuildOutput", "imageDetail.json", "ImageURI" ] },
                "ApplicationRepoName": "${ApplicationRepoName}",
                "Cluster": "${Cluster}",
                "ListenerArn": "${ListenerArn}",
                "TargetGroup": "${TargetGroup}",
                "ServiceDesiredCount": "${ServiceDesiredCount}",
                "ServiceLoadBalancerPath": "${ServiceLoadBalancerPath}",
                "ServiceContainerPort": "${ServiceContainerPort}",
                "ServiceSecurityGroups": { "Fn::Join" : [ ",", "${ServiceSecurityGroups}"] ] },
                "ServiceSubnets": { "Fn::Join" : [ ",", "${ServiceSubnets}" ] },
                "TaskContainerPort": "${TaskContainerPort}",
                "TaskCpu": "${TaskCpu}",
                "TaskMemory": "${TaskMemory}",
                "TaskExecutionRoleArn": "${TaskExecutionRoleArn}"
              }

So I expect that the List should be transformed to a String and String should be passed and then used in the nested stack, however, attempt to deploy such stack returned an error:

Template error: variable ServiceSecurityGroups in Fn::Sub expression does not resolve to a string

My question:

Is it possible to use Join function inside ParameterOverrides section to transform a List to a String?

If yes, I would much appreciate if you share with me some example that illustrates how to do this.

Thank you.

1
  • Can we pass a complete JSON file into ParameterOverrides? Commented May 26, 2023 at 11:31

1 Answer 1

2

Unfortunately you cannot use intrinsic functions within the Fn::Sub Syntax Reference

You can still use other intrinsic functions such as Fn::Join within Fn::Sub variable map. So your ParameterOverrides will be as follows instead:

ParameterOverrides: !Sub 
  - |
    {
      "ImageURI" : { "Fn::GetParam" : [ "BuildOutput", "imageDetail.json", "ImageURI" ] },
      "ApplicationRepoName": "${ApplicationRepoName}",
      "Cluster": "${Cluster}",
      "ListenerArn": "${ListenerArn}",
      "TargetGroup": "${TargetGroup}",
      "ServiceDesiredCount": "${ServiceDesiredCount}",
      "ServiceLoadBalancerPath": "${ServiceLoadBalancerPath}",
      "ServiceContainerPort": "${ServiceContainerPort}",
      "ServiceSecurityGroups": "${KEY_NAME_1}",
      "ServiceSubnets": "${KEY_NAME_2}",
      "TaskContainerPort": "${TaskContainerPort}",
      "TaskCpu": "${TaskCpu}",
      "TaskMemory": "${TaskMemory}",
      "TaskExecutionRoleArn": "${TaskExecutionRoleArn}"
    }
 - KEY_NAME_1: !Join [ ",", [ !Ref ServiceSecurityGroups ] ]
   KEY_NAME_2: !Join [ ",", [ !Ref ServiceSubnets ] ]

If your ServiceSecurityGroups and ServiceSubnets are already lists then remove the square braces around the !Ref statements.

Sign up to request clarification or add additional context in comments.

1 Comment

Can we pass a complete JSON file into ParameterOverrides?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.