Sub 和 Join 逗号分隔列表 [英] Sub and Join on Comma-Delimited List

查看:30
本文介绍了Sub 和 Join 逗号分隔列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 ECS(Fargate)任务定义,它使用传递给 Command 的可变数量的环境变量.每个变量名称都与 SecretsManager 中的一个秘密相匹配.

I'm trying to build an ECS (Fargate) Task Definition that uses a variable number of Environment Variables passed to Command. Each variable name matches a secret in SecretsManager.

我无法以有意义的方式组合这些功能.以下代码只是将所有变量作为字符串列表传递给 Command.

I've having trouble combining these functions in a meaningful way. The following code just passes all of the variables to Command as a list of strings.

 SpecEnvVars:
   Type: CommaDelimitedList
   Default: "greeting,name,title,rank"
   Description: |
     The Environmental Variables to pull into the container, defined by their
     associated Secrets names

 ContainerDefinitions:
   - Name: !Ref 'ServiceName'
     Command: !Split
       - ','
       - !Join
         - ','
         - !Ref SpecEnvVars

但是,我需要将列表中的项目解析为机密 JSON.解决秘密是这样完成的:

However, I need to resolve the items in the list to secrets JSON. Resolving the secrets is done like so:

!Sub '{{resolve:secretsmanager:test/${greeting}}}'

如何将 Fn::Sub 与 Split/Join 集成以返回 SecretsManager JSON 字符串列表?

How can I integrate Fn::Sub with the Split/Join to return a list of SecretsManager JSON strings?

推荐答案

我花了一段时间才找到正确的 Functions 组合,但我做到了:

It took me a while to find the correct combination of Functions but I did it:

ContainerDefinitions:
  - Name: !Ref 'ServiceName'
    Command: !Split
      - ','
      - !Sub
        - '{{resolve:secretsmanager:test/${inner}}}'
        - inner: !Join
          - '}},{{resolve:secretsmanager:test/'
          - Ref: "SpecEnvVars"

我想为这个答案提供支持:https://stackoverflow.com/a/50060983/9671763 因为它实际上给了我答案——我只需要根据我的用例调整它.

I want to give props to this answer: https://stackoverflow.com/a/50060983/9671763 because it actually gave me my answer - I just needed to adapt it for my use-case.

这篇关于Sub 和 Join 逗号分隔列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆