我正在尝试将通知规则设置为CDK堆栈中代码管道的一部分。
注意,这不是CDK管道,而是正在设置AWS CodePipeline的CDK堆栈。
为了创建一个CfnNotificationRule,我必须将CodePipeline的ARN作为resource参数传递。在下面的示例代码中,我将ARN硬编码为TARGET_ARN
然而,我想动态地提供这一点。
如何向my-pipeline CfnNotificationRule constructor?提供CDK为生成的ARN?
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
})
}
}发布于 2020-11-11 09:17:11
将管道初始化为局部变量,然后可以使用它的内部方法,例如,您的新代码将如下所示(我注意到在stageName: 'Deploy',下面有一个方括号stageName: 'Deploy',,它导致代码注释编译,因此我在示例中删除了它)
const myPipeline = new codepipeline.Pipeline(this, 'Pipeline', {
crossAccountKeys: false,
pipelineName: "my-pipeline",
stages: [{
stageName: 'Source',
},
{
stageName: 'Build',
},
{
stageName: 'Deploy',
}]
})
myPipeline.pipelineArnmyPipeline.pipelineArn会给你ARN
https://stackoverflow.com/questions/64781823
复制相似问题