Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New pattern submission:- Implementing AWS CDK Log Notification Pattern for Error Logs #2196

Closed
thavasnippets opened this issue Mar 23, 2024 · 1 comment

Comments

@thavasnippets
Copy link

Introduction

Monitoring logs for errors is crucial for maintaining the reliability and performance of cloud-based applications. AWS offers services like CloudWatch Logs for log management and Amazon SNS for notification delivery. By combining these services, you can set up automated error detection and notification systems, ensuring that you're promptly alerted to any issues in your applications.

AWS CDK simplifies the process of provisioning and managing AWS infrastructure by allowing you to define it using familiar programming languages such as Python. We'll leverage the AWS CDK to implement a log notification pattern that detects errors in log streams and sends notifications via email using Amazon SNS.

pattern

Implementation Steps

  1. Setting up the AWS CDK Environment:

    • Ensure you have the AWS CDK installed and configured on your local machine.
    • Create a new AWS CDK project or use an existing one.
  2. Defining the CDK Stack:

    • Import the necessary AWS CDK modules (aws_lambda, aws_sns, aws_iam, aws_logs).
    • Define a new CDK stack class that inherits from Stack.
    • Define constructor arguments for the stack, such as log group names, email for notifications, environment, cost center, and contact information.
  3. Creating an SNS Topic:

    • Create an Amazon SNS topic to which error notifications will be sent.
    • Apply custom tags to the SNS topic for better organization and management.
  4. Creating a Lambda Function:

    • Define an AWS Lambda function using the Function construct.
    • Specify the runtime, handler function, and code location (e.g., from an asset directory).
    • Pass the SNS topic ARN as an environment variable to the Lambda function.
    • Add IAM permissions to the Lambda function to allow it to publish messages to SNS and interact with CloudWatch Logs.
  5. Configuring CloudWatch Logs Subscription Filters:

    • Iterate over the provided log group names.
    • Create CloudWatch subscription filters for each log group to filter error messages.
    • Specify the Lambda function as the destination for filtered log events.
  6. Adding Email Subscription to SNS Topic:

    • Add an email subscription to the SNS topic to receive error notifications via email.

Pattern Repository:

https://github.com/thavasnippets/aws-cdk-log-notification-pattern

@thavasnippets thavasnippets changed the title New pattern submission New pattern submission:- Implementing AWS CDK Log Notification Pattern for Error Logs Mar 24, 2024
@julianwood
Copy link
Contributor

julianwood commented Jun 3, 2024

Please resubmit via the standard PR system:

To submit a template to the Serverless Patterns Collection, submit an issue with the following information.

IMPORTANT
Patterns are intended to be primarily IaC-focused implementations of 2-4 AWS services, with minimum custom code. They should be commonly used combinations that help developers get started quickly. If you have a utility, demo, or application, submit these to the Serverless Repos Collection instead.

ONLY SUBMIT ONE PATTERN CHANGE PER PR. Multiple patterns or files spanning multiple pattern directories will be automatically rejected.

Patterns may take up to 4-6 weeks to review, test, and merge but there is no SLA and can take significantly longer due to other work the team has.

To learn more about submitting a pattern, read the publishing guidelines page.

  1. Use the model template located at https://github.com/aws-samples/serverless-patterns/tree/main/_pattern-model to set up a README, template and any associated code.

  2. THIS PROCESS HAS BEEN SIMPLIFIED. All the information below must be provided in the "example-pattern.json" file cloned from the model **

Note the following information for the model:

  • Description (intro.text) should be a 300-500 word explanation of how the pattern works.
  • Resources should like to AWS documentation and AWS blogs related to the post (1-5 maximum).
  • Author bio may include a LinkedIn and/or Twitter reference and a 1-sentence bio.

You must ensure that the sections of the model README.md are completed in full.

GitHub PR for template:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants