An AI-powered Twitter bot built with AWS CDK that autonomously generates developer-focused tweets with code snippet images every Monday at 3:30 PM IST.
- Autonomous Scheduling: Runs serverlessly via AWS EventBridge (Cron)
- AI Content Generation: Uses GPT-4o-mini for tweet text + relevant code snippets
- Dynamic Media: Renders code to PNG via SourceCodeShots API
- Secure Secret Management: Runtime SSM SecureString decryption (no env var exposure)
- Zero-Cost Infrastructure: Fully within AWS Free Tier limits
- Type-Safe: Built with TypeScript, esbuild bundling, and strict linting
- EventBridge triggers Lambda every Monday @ 10:00 UTC (3:30 PM IST)
- Lambda fetches encrypted secrets from SSM Parameter Store at runtime
- OpenAI generates tweet text (<280 chars) + supporting code snippet
- SourceCodeShots renders code snippet to PNG image
- Twitter API v2 posts tweet with attached media
| Category | Technology |
|---|---|
| Language | TypeScript (Node.js 20) |
| Infra as Code | AWS CDK v2 |
| AI | OpenAI GPT-4o-mini |
| Media | SourceCodeShots API |
| Social | Twitter API v2 |
| Secrets | AWS SSM SecureString |
| Package Mgr | pnpm |
| Bundler | esbuild |
- Node.js 20+
- pnpm
- AWS CLI configured
.envfile with required keys (see below)
pnpm install
pnpm build# Test full tweet generation flow
pnpm post-tweet
# Watch mode for development
pnpm watchCreate a .env file:
OPENAI_API_KEY=sk-proj-...
CONSUMER_KEY=...
CONSUMER_KEY_SECRET=...
ACCESS_KEY=...
ACCESS_KEY_SECRET=...npx cdk bootstrap aws://ACCOUNT_ID/ap-south-1pnpm cdk:deploypnpm cdk:destroy- Secrets: Never stored in CFN templates; decrypted only at Lambda runtime
- IAM: Least-privilege roles (SSM:GetParameter only)
- Cost: ~$0.00/month AWS + ~$0.0004/tweet OpenAI
- Free Tier: Lambda (400k GB-s), EventBridge (1M events), SSM (10k params)
# Linting
pnpm lint
# Formatting
pnpm formatsrc/
├── bin/ # CDK app entrypoint
├── handler/
│ ├── schedule-handler.ts # Main orchestration logic
│ ├── services/ # OpenAI, Twitter, CodeSnippet
│ ── util/ # Prompts, Secrets loader
├── lib/
│ ├── components/ # Reusable ScheduledLambda construct
│ └── stacks/ # CloudFormation stack definition
└── index.ts # Local dev entrypoint
- Twitter Free Tier: few tweets/month limit
- No duplicate prevention (stateless design)
- Cold start latency (~3s first invocation)
