【发布时间】:2020-11-11 06:56:36
【问题描述】:
我正在尝试将通知规则设置为 CDK 堆栈中代码管道的一部分。
请注意,这不是 CDK 管道,而是设置 AWS CodePipeline 的 CDK 堆栈。
为了创建 CfnNotificationRule,我必须将 CodePipeline 的 ARN 作为 resource 参数传入。在下面的示例代码中,我将 ARN 硬编码为 TARGET_ARN
但是,我想动态提供。
如何将 CDK 为 my-pipeline 生成的 ARN 提供给 CfnNotificationRule 构造函数?
const codepipeline = require('@aws-cdk/aws-codepipeline');
class PipelineStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
//I want the ARN of this pipeline in TARGET_ARN
new codepipeline.Pipeline(this, 'Pipeline', {
crossAccountKeys: false,
pipelineName: "my-pipeline",
stages: [{
stageName: 'Source',
},
{
stageName: 'Build',
},
{
stageName: 'Deploy',
]
}
]
})
const AWS_SLACK_CHATBOT_ARN = 'arn:aws:chatbot::111111111111:chat-configuration/slack-channel/my-slack-channel'
const TARGET_ARN = 'arn:aws:codepipeline:us-east-2:111111111111:my-pipeline'
const notes = new notifications.CfnNotificationRule(this, 'my-dev-slack', {
detailType: "FULL",
name: "my-dev-slack",
eventTypeIds: [
"codepipeline-pipeline-action-execution-succeeded",
"codepipeline-pipeline-action-execution-failed",
"codepipeline-pipeline-stage-execution-failed"
],
targets: [{
targetType: "AWSChatbotSlack",
targetAddress: AWS_SLACK_CHATBOT_ARN
}],
resource: TARGET_ARN
})
}
}
【问题讨论】:
标签: amazon-cloudformation amazon-sns aws-codepipeline aws-cdk