是否有一种方法可以通过AWS聊天机器人定制slack消息?



我正在尝试使用使用cdk创建的aws聊天机器人发送slack通知。

在生产中,有许多lambda函数对特定的5xx错误或4xx错误具有cloudwatch警报。

我试图在我的环境中复制这种情况,通过部署一个lambda和附加一个cloudwatch警报,它向SNS发送通知,然后聊天机器人向slack发送通知。

到目前为止,一切都很好,但是我对聊天机器人收到的链接不满意。指向cloudwatch报警

是否可以添加到创建度量的cloudwatch警报的链接,以便在单击链接时可以将其重定向到cloudwatch日志而不是cloudwatch警报?

export class CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Lambda
const helloworldFn = new lambda.Function(this, "sample-lambda", {
code: new lambda.AssetCode("./lib/lambda"),
handler: "hello-world.handler",
runtime: lambda.Runtime.NODEJS_14_X,
});
// Lambda Log Group setting
const metricFilter = helloworldFn.logGroup.addMetricFilter(
"Keyword Filter",
{
metricNamespace: "chatbot-sample",
metricName: "filter-by-keyword",
filterPattern: { logPatternString: ""HELLO, Slack!"" },
}
);
// Chatbot Role & Policy
const chatbotRole = new iam.Role(this, "chatbot-role", {
roleName: "chatbot-sample-role",
assumedBy: new iam.ServicePrincipal("sns.amazonaws.com"),
});
chatbotRole.addToPolicy(
new iam.PolicyStatement({
resources: ["*"],
actions: [
"cloudwatch:Describe*",
"cloudwatch:Get*",
"cloudwatch:List*",
],
})
);
// SNS TOPIC
const topic = new sns.Topic(this, "notification-topic", {
displayName: "ChatbotNotificationTopic",
topicName: "ChatbotNotificationTopic",
});
const alarm = new cloudwatch.Alarm(this, "Alarm", {
metric: metricFilter.metric(),
actionsEnabled: true,
threshold: 0,
evaluationPeriods: 5,
datapointsToAlarm: 1,
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});
// 通知さきのトピックを指定
const action = new cwactions.SnsAction(topic);
alarm.addAlarmAction(action);
// Chatbot Slack Notification Integration
const bot = new chatbot.SlackChannelConfiguration(
this,
"sample-slack-notification",
{
slackChannelConfigurationName: 'amplify-github-jatin-notifications',
slackWorkspaceId: 'xxxxxx',
slackChannelId: 'xxxxxx',
notificationTopics: [topic],
}
);
}
}

没有。AWS Chatbot不允许您为消息指定自己的模板,您必须使用AWS定义的模板。

如果你想要自定义Slack消息,你需要编写自己的Slack集成,而不使用AWS聊天机器人。

相关内容

  • 没有找到相关文章

最新更新