How pedchenkoroman/aws-kaizen works
Main Components
• CDK Application Entry Point (bin/aws-kaizen.ts): This is where the app initializes and kicks off the stack deployment.
• AWS CloudFormation Stack Definition (lib/aws-kaizen-stack.ts): This file defines the infrastructure — the “stack” of AWS resources that will be deployed.
• AWS Lambda Function (lambda/turn-on-off-handler.ts): This function acts as the operational logic to start or stop EC2 instances. It is the core “engine” that implements the EC2 control logic.
• Test Suite (test/aws-kaizen.test.ts): While not directly part of runtime architecture, tests ensure that the core functionality and infrastructure definitions work as expected.
• CDK and Build Configurations (cdk.json, tsconfig.json, jest.config.js, etc.): These files/configuration artifacts guide the build, deployment, and test processes.
Relationships and Interactions
• The CDK application (initiated in the bin directory) synthesizes a CloudFormation template using the definitions in the lib directory.
• The stack then includes the Lambda function (from the lambda directory) as an AWS resource.
• Although not explicitly in the code, the Lambda will have triggers (which may be defined by events such as CloudWatch Events or scheduled rule, based on the underlying infrastructure setup) to start/stop EC2 instances.
• Upon deployment via the CDK commands (deploy, diff, synth), the CloudFormation stack manages the lifecycle of these resources (Lambda, any associated IAM Roles, and the EC2 instance management hooks).
Architectural Patterns & Design Principles
• Infrastructure as Code (IaC): The project leverages AWS CDK to define infrastructure programmatically.
• Separation of Concerns: The project splits infrastructure definitions (lib), operational logic (lambda), and deployment entry logic (bin).
• Test-Driven Development (TDD) for infrastructure: With Jest tests validating functionality.
• Modularity: Each component is clearly isolated (e.g., Lambda logic separated from stack definition), facilitating extensibility.
Including Relevant Technologies and Frameworks
• AWS Cloud Development Kit (CDK) for infrastructure definition.
• AWS Lambda for serverless functions executing the start/stop EC2 logic.
• AWS CloudFormation as the underlying deployment mechanism.
• Typescript as the programming language.
• Jest for testing.
• Node.js (implied by npm scripts and package.json).