如何在CDK中提取字符串列表的参数?

发布于 2025-02-13 08:13:12 字数 1090 浏览 3 评论 0原文

我正在尝试在CDK应用中提取StringList的现有SSM参数。

我可以存储一个值,但是为了避免重复代码,我试图将3个值存储在单个变量中,并以符号访问数组value [0]

        const stringValue = ssm.StringParameter.fromStringParameterAttributes(this, 'MyValue', 
    
        const stringValue2 = ssm.StringListParameter.fromStringListParameterName(this, 'myValue', '/dev/name')
    
        const ssmstringlistoutput = new cdk.CfnOutput(this, 'ssmoutput', {
          value: cdk.Fn.select(0, stringValue2.stringListValue),
          description: 'name of ssmlist',
          exportName: 'avatarsBucket',
        });
    
    
        // Chatbot Slack Notification Integration
        const bot = new chat.SlackChannelConfiguration(
          this,
          "sample-slack-notification",
          {
            slackChannelConfigurationName: 'my channel name', 
            slackWorkspaceId: 'stringValue2[0]',
            slackChannelId: 'stringValue[1]',
            notificationTopics: [topic],
          }
        );
      }

输出用于验证。它将整个列表作为一个字符串值输出,而不仅仅是预期的提取的第一个元素。

I am trying to extract existing SSM parameters of stringList in my cdk app.

I can store a single value, but to avoid duplication of code I am trying to store 3 values in single variable and access them as array in the form value[0]

        const stringValue = ssm.StringParameter.fromStringParameterAttributes(this, 'MyValue', 
    
        const stringValue2 = ssm.StringListParameter.fromStringListParameterName(this, 'myValue', '/dev/name')
    
        const ssmstringlistoutput = new cdk.CfnOutput(this, 'ssmoutput', {
          value: cdk.Fn.select(0, stringValue2.stringListValue),
          description: 'name of ssmlist',
          exportName: 'avatarsBucket',
        });
    
    
        // Chatbot Slack Notification Integration
        const bot = new chat.SlackChannelConfiguration(
          this,
          "sample-slack-notification",
          {
            slackChannelConfigurationName: 'my channel name', 
            slackWorkspaceId: 'stringValue2[0]',
            slackChannelId: 'stringValue[1]',
            notificationTopics: [topic],
          }
        );
      }

The output is for verification. It outputs the entire list as one string value, not just the extracted first element as expected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2025-02-20 08:13:12

代替StringListParameter.fromstringListParamEtername,创建 cfnParameter 构造。将参数名称作为默认值传递:

const listParam = new cdk.CfnParameter(this, 'ListParam', {
  type: 'AWS::SSM::Parameter::Value<List<String>>',
  default: '/dev/name',
});

然后在将值传递为Prop输入时选择一个元素:

slackWorkspaceId: cdk.Fn.select(0, listParam.valueAsList),
slackChannelId: cdk.Fn.select(1, listParam.valueAsList),

正在发生什么? href =“ https://docs.aws.amazon.com/awscloudformation/latest/userguide/dynamic-references.html#dynamic-references-references-references-ssm” {{resolve:ssm:/dev/name}} 。正如您发现的那样,云形式显然不能将拆分应用于动态参考。

Instead of StringListParameter.fromStringListParameterName, create a CfnParameter construct. Pass the parameter name as the default value:

const listParam = new cdk.CfnParameter(this, 'ListParam', {
  type: 'AWS::SSM::Parameter::Value<List<String>>',
  default: '/dev/name',
});

Then select an element when passing the value as prop inputs:

slackWorkspaceId: cdk.Fn.select(0, listParam.valueAsList),
slackChannelId: cdk.Fn.select(1, listParam.valueAsList),

What's going on? fromStringListParameterName synthesises to a CloudFormation dynamic reference like {{resolve:ssm:/dev/name}}. And as you discovered, CloudFormation apparently cannot apply a split to dynamic references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文