CI/CD (Continuous Integration/Continuous Deployment) automates the build, test, and deploy process. This section guides you through setting up CI/CD for Lexi.
πΈ TODO: Add CI/CD pipeline diagram
Developer β Git Push
β
GitHub/GitLab
β
βββββββββββββββββββ΄ββββββββββββββββββ
β β
βΌ βΌ
GitHub Actions Amplify
β β
ββ Backend Workflow ββ Auto-detect push
β ββ Checkout code ββ Build Next.js
β ββ Setup Python ββ Deploy to CDN
β ββ SAM Build ββ Invalidate cache
β ββ SAM Deploy
β
ββ Frontend Workflow
ββ Checkout code
ββ Setup Node.js
ββ Build Next.js
ββ Trigger Amplify
CI/CD is divided into 3 main parts:
GitHub Actions - CI/CD automation
SAM Deployment - Backend deployment
Amplify Auto-Deploy - Frontend deployment
Code Change β GitHub
β
GitHub Actions
β
sam build
β
sam deploy
β
CloudFormation Update
β
Lambda Functions Updated
Rollback: CloudFormation automatic rollback on failure
Code Change β GitHub
β
Amplify Webhook
β
npm ci
β
npm run build
β
Deploy to CDN
β
Invalidate Cache
Rollback: Redeploy previous version
on:
push:
branches: [main, develop]
paths:
- 'lexi-be/**'
workflow_dispatch: # Manual trigger
on:
push:
branches: [main]
paths:
- 'lexi-fe/**'
pull_request:
branches: [main]
developlexi-be-dev stackdevelop.d<APP_ID>.amplifyapp.comstaginglexi-be-staging stackstaging.d<APP_ID>.amplifyapp.commainlexi-be stackmain.d<APP_ID>.amplifyapp.com or custom domain# View workflow runs
gh run list
# View specific run
gh run view <RUN_ID>
# View logs
gh run view <RUN_ID> --log
# List stacks
aws cloudformation list-stacks --region <REGION>
# Describe stack events
aws cloudformation describe-stack-events \
--stack-name lexi-be \
--region <REGION>
# List apps
aws amplify list-apps --region <REGION>
# List jobs
aws amplify list-jobs \
--app-id <APP_ID> \
--branch-name main \
--region <REGION>
# Add test step before deploy
- name: Run tests
run: |
cd lexi-be
python -m pytest tests/
# Require manual approval for production
environment:
name: production
url: https://lexi.example.com
# Notify on failure
- name: Notify on failure
if: failure()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
# Check workflow logs in GitHub Actions
# Common issues:
# - AWS credentials invalid
# - Build errors
# - Deployment timeout
Optimization:
# Backend
aws cloudformation cancel-update-stack \
--stack-name lexi-be
# Frontend
# Redeploy previous version in Amplify Console
After completing the CI/CD section, you should:
πΈ TODO: Add CI/CD pipeline diagram
πΈ TODO: Add screenshot of successful GitHub Actions workflow
You’ve completed the CI/CD section! Continue to Monitoring & Cost Optimization to learn monitoring and cost optimization.