3

CodeDeploy でビルドが成功または失敗するたびに、通信媒体 (電子メール、slack など) を介してユーザーに通知するツールを構築したいと考えています。私は彼らのドキュメントに目を通しました..ロングポーリング以外は何も思い浮かびません。URLを登録して通知を受け取ることができるWebhookオプションがあるかどうか、何か考えはありますか?

4

4 に答える 4

6

2016-04-27 の更新

AWSはこれを 2016 年 2 月に正式に発表しました

アプリケーションのデプロイプロセスの前、最中、後に Amazon SNS 通知を送信するトリガーを作成できるようになりました。トリガーは、展開全体または展開の対象となる個々のインスタンスに対して設定でき、成功と失敗の両方で送信されます。

元の答え

まだ。

このAWS フォーラム スレッドでは、詳細をポーリングする代わりに Lambda を使用してイベントを処理できるように、CodeDeploy がイベントを発行するように要求されました。

AWS スタッフによる回答 (強調は私のもの):

ここCodeDeployで同意します。残念ながら、正確なリリース日をお伝えすることはできませんが、近日中に発表される予定です。

于 2015-10-05T19:18:11.103 に答える
3

フォーマットされた CodeDeploy 通知を Slack に投稿する AWS Lambda 関数の要点を次に示します。

https://gist.github.com/MrRoyce/097edc0de2fe001288be2e8633f4b22a

var services = '/services/...';  // Update this with your Slack service...
var channel = "#aws-deployments"  // And this with the Slack channel

var https = require('https');
var util = require('util');

var formatFields = function(string) {
  var
    message = JSON.parse(string),
    fields  = [],
    deploymentOverview;

  // Make sure we have a valid response
  if (message) {
    fields = [
      {
        "title" : "Task",
        "value" : message.eventTriggerName,
        "short" : true
      },
      {
        "title" : "Status",
        "value" : message.status,
        "short" : true
      },
      {
        "title" : "Application",
        "value" : message.applicationName,
        "short" : true
      },
      {
        "title" : "Deployment Group",
        "value" : message.deploymentGroupName,
        "short" : true
      },
      {
        "title" : "Region",
        "value" : message.region,
        "short" : true
      },
      {
        "title" : "Deployment Id",
        "value" : message.deploymentId,
        "short" : true
      },
      {
        "title" : "Create Time",
        "value" : message.createTime,
        "short" : true
      },
      {
        "title" : "Complete Time",
        "value" : ((message.completeTime) ? message.completeTime : ''),
        "short" : true
      }
    ];

    if (message.deploymentOverview) {
     deploymentOverview = JSON.parse(message.deploymentOverview);
     
      fields.push(
        {
          "title" : "Succeeded",
          "value" : deploymentOverview.Succeeded,
          "short" : true
        },
        {
          "title" : "Failed",
          "value" : deploymentOverview.Failed,
          "short" : true
        },
        {
          "title" : "Skipped",
          "value" : deploymentOverview.Skipped,
          "short" : true
        },
        {
          "title" : "In Progress",
          "value" : deploymentOverview.InProgress,
          "short" : true
        },
        {
          "title" : "Pending",
          "value" : deploymentOverview.Pending,
          "short" : true
        }
      );
    }
  }

  return fields;

}

exports.handler = function(event, context) {

    var postData = {
        "channel": channel,
        "username": "AWS SNS via Lamda :: CodeDeploy Status",
        "text": "*" + event.Records[0].Sns.Subject + "*",
        "icon_emoji": ":aws:"
    };

    var fields = formatFields(event.Records[0].Sns.Message);
    var message = event.Records[0].Sns.Message;
    var severity = "good";

    var dangerMessages = [
        " but with errors",
        " to RED",
        "During an aborted deployment",
        "FAILED",
        "Failed to deploy application",
        "Failed to deploy configuration",
        "has a dependent object",
        "is not authorized to perform",
        "Pending to Degraded",
        "Stack deletion failed",
        "Unsuccessful command execution",
        "You do not have permission",
        "Your quota allows for 0 more running instance"];

    var warningMessages = [
        " aborted operation.",
        " to YELLOW",
        "Adding instance ",
        "Degraded to Info",
        "Deleting SNS topic",
        "is currently running under desired capacity",
        "Ok to Info",
        "Ok to Warning",
        "Pending Initialization",
        "Removed instance ",
        "Rollback of environment"
        ];

    for(var dangerMessagesItem in dangerMessages) {
        if (message.indexOf(dangerMessages[dangerMessagesItem]) != -1) {
            severity = "danger";
            break;
        }
    }

    // Only check for warning messages if necessary
    if (severity == "good") {
        for(var warningMessagesItem in warningMessages) {
            if (message.indexOf(warningMessages[warningMessagesItem]) != -1) {
                severity = "warning";
                break;
            }
        }
    }

    postData.attachments = [
        {
            "color": severity,
            "fields": fields
        }
    ];

    var options = {
        method: 'POST',
        hostname: 'hooks.slack.com',
        port: 443,
        path: services  // Defined above
    };

    var req = https.request(options, function(res) {
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        context.done(null);
      });
    });

    req.on('error', function(e) {
      console.log('problem with request: ' + e.message);
    });

    req.write(util.format("%j", postData));
    req.end();
};

于 2016-08-10T14:18:18.590 に答える
0

ネイティブ ソリューションはありませんが、これを達成するために使用できる回避策があります。ラムダを使用してこれらのイベントをトリガーできます。AWS ブログでは、ファイルを S3 にアップロードするときにラムダ経由で codedeploy をトリガーする方法を示しています ( https://blogs.aws.amazon.com/application-management/post/Tx3TPMTH0EVGA64/Automatically-Deploy-from-Amazon- S3-using-AWS-CodeDeploy )。これと同じ概念を使用して、ラムダ関数でエラー/成功バケットをリッスンし、codedeploy パッケージを変更してファイルを s3 にアップロードし、それをイベント トリガーとして使用して SES 経由でメールを送信できます ( https:/ /peekandpoke.wordpress.com/2015/02/26/dancing-the-lambada-with-aws-lambda-or-sending-emails-on-s3-events/)またはあなたが望むことをするウェブサービス/ページに連絡してください。少しばかげているかもしれませんが、仕事は完了します。

于 2015-10-10T03:55:12.307 に答える
0

大まかに言えば、次のことを行う必要があります。

  • SNS トピックを設定する
  • CodeDeploy トリガーを作成する
  • sns:PublishCodeDeploy IAM ロールにアクセス許可を追加する
  • Incoming Webhook で Slack を構成する
  • CodeDeploy の SNS メッセージを処理し、Slack メッセージを作成して受信 Webhook で Slack に送信する Lambda 関数を作成および設定する

上記の要点と同様のコードを使用して、CodeDeploy イベントの Slack 通知用の Lambda 関数をセットアップしました。こちらのスクリーンショットを含め、手順全体を文書化しました。

同様のエンドツーエンドのガイドを他の場所で見つけることができなかったので、これがこの質問に出くわした他の誰かに役立つことを願っています.

于 2019-12-10T05:21:22.697 に答える