Amazon cloudformation 如何在同一CDK堆栈中获取代码管道的ARN

Amazon cloudformation 如何在同一CDK堆栈中获取代码管道的ARN,amazon-cloudformation,amazon-sns,aws-codepipeline,aws-cdk,Amazon Cloudformation,Amazon Sns,Aws Codepipeline,Aws Cdk,我正在尝试将通知规则设置为CDK堆栈中代码管道的一部分 注意,这不是一个CDK管道,而是一个正在设置AWS代码管道的CDK堆栈 为了创建CfnNotificationRule,我必须将代码管道的ARN作为资源参数传入。在下面的示例代码中,我将ARN硬编码为TARGET\u ARN 然而,我想动态地提供这一点 如何将CDK为my pipeline生成的ARN提供给CfnNotificationRule构造函数? const codepipeline = require('@aws-cdk/aws-

我正在尝试将通知规则设置为CDK堆栈中代码管道的一部分

注意,这不是一个CDK管道,而是一个正在设置AWS代码管道的CDK堆栈

为了创建CfnNotificationRule,我必须将代码管道的ARN作为
资源
参数传入。在下面的示例代码中,我将ARN硬编码为
TARGET\u 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

        })
    }
}

将管道初始化为局部变量,然后您可以在之后使用其内部方法,例如,您的新代码如下所示(我注意到您在
stageName:'Deploy',
下有一个括号
[
,它导致代码注释编译,因此我在示例中删除了它)


myPipeline.pipelineArn
将为您提供ARN

将管道初始化为局部变量,然后您可以使用其内部方法,例如,您的新代码如下所示(我注意到您有一个括号
[
stageName:'Deploy'下,
导致代码注释编译,因此我在示例中删除了它)

myPipeline.pipelineArn
将为您提供ARN

        const myPipeline = new codepipeline.Pipeline(this, 'Pipeline', {
            crossAccountKeys: false,
            pipelineName: "my-pipeline",
            stages: [{
                stageName: 'Source',
            },
                {
                    stageName: 'Build',
                },
                {
                    stageName: 'Deploy',
                    
                }]
        })

        myPipeline.pipelineArn