# dongho-jung/terraform-aws-simple-lambda architecture

> Architecture diagram of the GitHub repository dongho-jung/terraform-aws-simple-lambda, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dongho-jung/terraform-aws-simple-lambda
- Repository: https://github.com/dongho-jung/terraform-aws-simple-lambda

## Overview

##### Main Components

a. Infrastructure Layer (Terraform):
- ECR Repository (from ecr_repository.tf)
- IAM Roles and Policies (from iam.tf)
- Lambda Function (from lambda.tf)
- CloudWatch components (from cloudwatch_*.tf files)

b. Integration Layer:
- Event source triggers including:
- CloudWatch Event Rules
- CloudWatch Alarms
- SNS Topic Subscriptions
- Cron Schedules

c. Runtime Layer:
- Docker container configuration
- Lambda execution environment
- Python runtime

##### Relationships and Flows

- Terraform module input → Resource creation flow
- Event source → Lambda function triggers
- Lambda function → CloudWatch Logs
- Docker image → ECR Repository → Lambda function

##### Important Elements to Highlight

a. Resource Creation Flow:
**Terraform Module Input → IAM Roles/Policies → ECR Repository → Docker Image → Lambda Function → CloudWatch Resources**

b. Event Triggering Flow:
**Event Sources (Cron/CloudWatch Alarm/SNS) → CloudWatch Events → Lambda Function → CloudWatch Logs**

##### Specific Implementation Details

- Docker layer caching mechanism
- AWS SSO integration
- File change detection system
- Tag management system

##### Notes Section

Callouts highlighting key features:
- Automatic Docker layer caching
- Support for custom runtimes
- Built-in AWS SSO support
- File change detection
- Size limitations (10GB Docker image limit)

For the principal software engineer, emphasize:
- The module's ability to handle different event sources
- The automated resource provisioning flow
- The security and permission model
- The monitoring and logging setup
- The Docker image building and caching strategy

This will create a comprehensive yet clear visualization of how the module automates Lambda function deployment while handling all necessary AWS resource creation and configuration.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        direction TB
        L1[AWS Service]:::aws
        L2[Terraform Resource]:::terraform
        L3[Event Source]:::event
        L4[IAM Component]:::iam
        L5[Docker Component]:::docker
    end

    subgraph Infrastructure
        direction TB
        TF[Terraform Module]:::terraform
        click TF "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/main.tf"
        
        subgraph IAM
            direction TB
            IAMR[IAM Roles]:::iam
            IAMP[IAM Policies]:::iam
            click IAMR "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/iam.tf"
            click IAMP "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/iam.tf"
        end

        subgraph Container
            direction TB
            ECR[ECR Repository]:::aws
            DOCK[Docker Image]:::docker
            click ECR "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/ecr_repository.tf"
            click DOCK "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/docker.tf"
        end

        subgraph Function
            direction TB
            LAMBDA[Lambda Function]:::aws
            LCONF[Lambda Configuration]:::terraform
            click LAMBDA "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/lambda.tf"
            click LCONF "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/lambda_module.tf"
        end

        subgraph Monitoring
            direction TB
            CWL[CloudWatch Logs]:::aws
            CWE["CloudWatch Events"]:::aws
            CWA[CloudWatch Alarms]:::aws
            click CWE "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/cloudwatch_event_rule.tf"
            click CWL "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/cloudwatch_log_subscription_filter.tf"
        end

        subgraph Events
            direction TB
            SNS[SNS Topics]:::aws
            CRON[Cron Schedules]:::event
            PERM[Lambda Permissions]:::iam
            click SNS "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/sns_topic_subscription.tf"
            click PERM "https://github.com/dongho-jung/terraform-aws-simple-lambda/blob/main/lambda_permission.tf"
        end
    end

    subgraph Examples
        direction TB
        MIN[Minimum Example]:::example
        ALARM[CloudWatch Alarm Example]:::example
        CRONJOB[Cron Job Example]:::example
        EVENT[Event Sources Example]:::example
        EXTRA[Extended Permissions Example]:::example
        PYUV[Python UV Example]:::example
        click MIN "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/minimum/"
        click ALARM "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/cloudwatch-alarm/"
        click CRONJOB "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/cron/"
        click EVENT "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/event-sources/"
        click EXTRA "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/extra-permissions/"
        click PYUV "https://github.com/dongho-jung/terraform-aws-simple-lambda/tree/main/examples/python-uv/"
    end

    %% Relationships
    TF --> IAMR & IAMP
    TF --> ECR
    DOCK --> ECR
    ECR --> LAMBDA
    LAMBDA --> CWL
    CWE --> LAMBDA
    CWA --> CWE
    SNS --> LAMBDA
    CRON --> CWE
    PERM --> LAMBDA
    LCONF --> LAMBDA

    %% Styles
    classDef aws fill:#FF9900,stroke:#232F3E,color:white
    classDef terraform fill:#844FBA,stroke:#232F3E,color:white
    classDef event fill:#3F8624,stroke:#232F3E,color:white
    classDef iam fill:#0058AB,stroke:#232F3E,color:white
    classDef docker fill:#0DB7ED,stroke:#232F3E,color:white
    classDef example fill:#666666,stroke:#232F3E,color:white
```
