RakshatJayakumar/aws-lambda-security-library
GitHub: RakshatJayakumar/aws-lambda-security-library
一个面向 AWS Lambda 的轻量级 Python 安全库,通过装饰器模式集成运行时威胁检测、CloudWatch 审计日志和基于 Bandit 的静态分析,帮助开发者以低侵入方式加固无服务器工作负载。
Stars: 0 | Forks: 0
# AWS Lambda 安全库




一个轻量级的 AWS Lambda Python 安全库 —— 提供**运行时威胁检测**、**通过 CloudWatch 进行审计日志记录**以及**静态分析工具**,以强化无服务器工作负载。
本项目作为爱尔兰国立学院云计算硕士学位研究项目的一部分而构建。
## 功能
- **运行时威胁检测** —— 包装 Lambda 处理程序以实时监控执行行为
- **CloudWatch 审计日志** —— 带有结构化输出的集中式安全事件日志记录
- **静态分析** —— 扫描常见的 Lambda 安全配置错误(弱哈希、`eval()` 的使用、暴露的秘密)
- 执行时间和内存占用与未优化的基线相比**减少了 20%**
- **兼容 Docker** —— 容器化部署,确保本地测试和部署环境的一致性
## 架构
```
Lambda Function
│
▼
┌─────────────────────────┐
│ Security Library Layer │
│ ┌───────────────────┐ │
│ │ @secure_lambda │ │ ← Runtime wrapper (decorator)
│ │ dynamic monitor │ │ ← Live threat detection
│ │ static analysis │ │ ← Pre-execution code scanning
│ └───────────────────┘ │
└──────────┬──────────────┘
│
▼
AWS CloudWatch Logs
(Audit trail + alerts)
```
## 项目结构
```
aws-lambda-security-library/
│
├── my_lambda_security_lib/ # Core security library
│ ├── lambda_wrapper.py # @secure_lambda decorator + dynamic monitoring
│ └── static_analysis.py # Bandit-based static analysis runner
│
├── test_function.py # Lambda handler unit tests
├── test_static_analysis.py # Static analysis test suite
├── utils.py # Shared utility functions
├── requirements.txt # Dependencies
└── .github/workflows/test.yml # CI pipeline (GitHub Actions)
```
## 快速开始
### 前置条件
- Python 3.11+
- 拥有 Lambda 和 CloudWatch 访问权限的 AWS 账户
- Docker(可选,用于容器化测试)
### 安装
```
git clone https://github.com/RakshatJayakumar/aws-lambda-security-library.git
cd aws-lambda-security-library
pip install -r requirements.txt
```
### 运行测试
```
python -m pytest
```
### 运行静态分析
```
from my_lambda_security_lib.static_analysis import run_static_analysis
issues = run_static_analysis()
print(issues)
```
### 使用 Lambda 包装器
```
from my_lambda_security_lib.lambda_wrapper import secure_lambda
@secure_lambda
def handler(event, context):
# Your Lambda logic here
return {"statusCode": 200, "body": "OK"}
```
`@secure_lambda` 装饰器会自动为您的处理程序配备运行时监控和 CloudWatch 审计日志功能 —— 无需额外配置。
## 可检测内容
| 威胁 | 检测方法 |
|---|---|
| 弱加密算法 (MD5, SHA1) | 静态分析 (Bandit) |
| 使用了 `eval()` | 静态分析 (Bandit) |
| 暴露的环境变量 | 运行时监控 |
| 可疑的文件操作 | 运行时监控 |
| 未处理的异常 | 运行时包装器 |
## CI/CD
每次推送都会触发 GitHub Actions 流水线,该流水线将自动安装依赖项并运行完整的测试套件。
```
on: [push, pull_request]
python-version: '3.11'
steps: pip install → pytest
```
## 技术栈
| 层级 | 技术 |
|---|---|
| 语言 | Python 3.11 |
| 云平台 | AWS Lambda, AWS CloudWatch |
| 安全扫描 | Bandit |
| 测试 | pytest |
| 容器化 | Docker |
| CI/CD | GitHub Actions |
## 作者
**Rakshat Jayakumar**
云计算硕士 —— 爱尔兰国立学院,都柏林
AWS 认证解决方案架构师 – 助理级
[](https://linkedin.com/in/rakshat-jayakumar)
[](https://github.com/RakshatJayakumar)
标签:AWS Lambda, CloudWatch, Docker, GitHub Advanced Security, Lambda装饰器, MIT许可, MSc研究项目, Python, Python安全库, Serverless, StruQ, 云安全监控, 云计算, 云计算安全, 安全专业人员, 安全加固, 安全助手, 安全规则引擎, 安全防御评估, 审计日志, 无后门, 无服务器安全, 机密泄露防护, 规则引擎, 请求拦截, 运行时威胁检测, 静态分析