如何在CDK中提取字符串列表的参数?
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代替
StringListParameter.fromstringListParamEtername
,创建 cfnParameter 构造。将参数名称作为默认值传递:然后在将值传递为Prop输入时选择一个元素:
正在发生什么? 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:Then select an element when passing the value as prop inputs:
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.