Events Notify AWS Construct for AWS CDK

2.2.767 · active · verified Thu Apr 16

cdk-events-notify is an AWS CDK Construct Library (currently v2.2.767) that provides a mechanism to trigger Lambda functions for push notifications to Line Notify or Slack. It primarily focuses on detecting AWS Console Login or switch role events via CloudTrail. The library is actively maintained with frequent updates, as indicated by its versioning and recent activity on PyPI and GitHub.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `cdk-events-notify` to send notifications to Line Notify for AWS console login events. It requires setting the `LINE_NOTIFY_TOKEN` environment variable and deploying the CDK stack. Ensure you have CloudTrail management events enabled for your account.

import os
import aws_cdk as cdk
from constructs import Construct
from cdk_events_notify import EventNotify

class MyEventNotifyStack(cdk.Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Retrieve Line Notify Token from environment variable for security
        line_notify_token = os.environ.get('LINE_NOTIFY_TOKEN', '')
        if not line_notify_token:
            raise ValueError("LINE_NOTIFY_TOKEN environment variable is not set.")

        # Create an EventNotify construct for Line notifications
        EventNotify(self, 'LineEventNotify', 
                    line_notify_token=line_notify_token)

app = cdk.App()
MyEventNotifyStack(app, 'MyEventNotifyStack',
                     env=cdk.Environment(account=os.environ.get('CDK_DEFAULT_ACCOUNT'),
                                         region=os.environ.get('CDK_DEFAULT_REGION'))
                    )
app.synth()

view raw JSON →