1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Codepipelineの通知をchatbot経由slackに。CDKを使って。

Last updated at Posted at 2020-11-10

以下の記事は古く、最新バージョンをご利用の際はこちらを参考にしてください。


以下のようなファイルを用意して。

chatbot-stack.ts
import * as cdk from "@aws-cdk/core";
import * as chatbot from "@aws-cdk/aws-chatbot";
import * as codestarnotifications from "@aws-cdk/aws-codestarnotifications";

export interface ChatBotStackProps extends cdk.StackProps {
  name: string;        // 適当な他とかぶらない文字列

  workspaceId: string; // 繋ぎ込みすると management consoleから確認できます。
  channelId: string;   // チャンネルID。copy linkして最後のセクションの文字列。

  pipelineArn: string; // 対象pipelineのarn
}

export class ChatBotStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props: ChatBotStackProps) {
    super(scope, id, props);

    const slackChannel = new chatbot.SlackChannelConfiguration(
      this,
      "NotificationSlackChannel",
      {
        slackChannelConfigurationName: props.name,
        slackWorkspaceId: props.workspaceId,
        slackChannelId: props.channelId,
      }
    );

    const rule = new codestarnotifications.CfnNotificationRule(
      this,
      "NotificationRule",
      {
        name: name,
        detailType: "FULL",
        eventTypeIds: [
          "codepipeline-pipeline-action-execution-succeeded",
          "codepipeline-pipeline-action-execution-failed",
        ],
        resource: props.pipelineArn,
        targets: [
          {
            targetType: "AWSChatbotSlack",
            targetAddress: slackChannel.slackChannelConfigurationArn,
          },
        ],
      }
    );
  }
}

こんな感じでpipelineのarnとその他情報を与えてやる感じです。

cdk.ts

...

const chatbot = new ChatBotStack(app, "ChatBotStack", {
  applicationName: "sampleapp",
  workspaceId: "XXXXXXX",
  channelId: 'deploy-notifications',
  pipelineArn: "arn:xxxxxxxxxxxxxxxxxx",
  env: {
    account: "ZZZZZZZZZ",
    region: "ap-northeast-1",
  },
});

...

slackとのつなぎ込みは、management consoleからやってしまいました。
AWS Chatbot のセットアップ を参考にしてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?