What :- I am trying to create SSM Parameters which contains dummy values. and then accesing them and referencing them in chatbot configuration.
Once it is stored, i want to access it in chatbot.
new ssm.StringListParameter(this, 'store-slack-ssm-param', {
parameterName: "slackChannelChatbotConfiguration",
stringListValue: ['slackChannelNameTobeAddedFromConsole', 'slack channelIdFromConsole'],
});
const slackParam = new CfnParameter(this, 'access-slack-ssm-param', {
type: 'AWS::SSM::Parameter::Value<List<String>>',
default: 'slackChannelChatbotConfiguration',
})
new chatbot.SlackChannelConfiguration(this, 'chatbot-slack-notification', {
slackChannelConfigurationName: Fn.select(0, slackParam.valueAsList),
slackWorkspaceId: this.slackWorkspaceId,
slackChannelId: Fn.select(1, slackParam.valueAsList),
notificationTopics: [this.snsTopic],
})
During deployment it shows this error
[ValidationError]: Unable to fetch parameters [slackChannelChatbotConfiguration] from parameter store for this account.
Note:- if i manually store these ssm paramters and directly access them in my cdk code this works, only creation and then accessing in cdk code is not working.
Update : according to this https://docs.aws.amazon.com/cdk/v2/guide/get_ssm_value.html
These methods return tokens, not the actual value. The value is resolved by AWS CloudFormation during deployment.
The value from ssm is resolved during deployment, so when you are creating it is not available to access, but if you already have like existing parameters, this works.
CodePudding user response:
You don't need the CfnParameter
construct - it requires the parameter to exist before the deployment, as you've found.
Simply use the parameter you're creating as follows:
const slackParam = new ssm.StringListParameter(this, 'store-slack-ssm-param', {
parameterName: "slackChannelChatbotConfiguration",
stringListValue: ['slackChannelNameTobeAddedFromConsole', 'slack channelIdFromConsole'],
});
new chatbot.SlackChannelConfiguration(this, 'chatbot-slack-notification', {
slackChannelConfigurationName: Fn.select(0, slackParam.stringListValue),
slackWorkspaceId: this.slackWorkspaceId,
slackChannelId: Fn.select(1, slackParam.stringListValue),
notificationTopics: [this.snsTopic],
});