HardПрактика4 min

Модификации автоматизации

Расширения автоматизации CRC: event-driven, multi-stage CI/CD, drift detection, data pipelines и ML deployment

Developer/Security Mod: Chain Reaction

Задача

Реализовать event-driven архитектуру: при создании нового визита автоматически запускается цепочка обработки -- валидация, обогащение, уведомление.

Реализация: EventBridge + Step Functions

# SAM template - event chain
EventBridgeRule:
  Type: AWS::Events::Rule
  Properties:
    EventPattern:
      source: ["crc.visitor"]
      detail-type: ["VisitorCountMilestone"]
    Targets:
      - Arn: !GetAtt NotificationFunction.Arn
        Id: "MilestoneNotification"

NotificationFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: notification.handler
    Events:
      Milestone:
        Type: EventBridgeRule
        Properties:
          Pattern:
            source: ["crc.visitor"]
# In visitor counter Lambda: emit event on milestone
import boto3

events = boto3.client('events')

def emit_milestone(count):
    if count % 100 == 0:  # Every 100 visitors
        events.put_events(Entries=[{
            'Source': 'crc.visitor',
            'DetailType': 'VisitorCountMilestone',
            'Detail': json.dumps({'count': count, 'milestone': True})
        }])

DevOps Mod: All The World's A Stage

Задача

Multi-stage CI/CD с environment-specific конфигурацией, manual approvals для production и автоматическим rollback.

Реализация

# .github/workflows/multi-stage.yml
name: Multi-Stage Deploy

on:
  push:
    branches: [main, develop]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: python -m pytest tests/ -v

  deploy-dev:
    needs: test
    if: github.ref == 'refs/heads/develop'
    runs-on: ubuntu-latest
    environment: dev
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to dev
        run: sam deploy --config-env dev

  deploy-staging:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to staging
        run: sam deploy --config-env staging
      - name: Run smoke tests
        run: python -m pytest tests/smoke/ --env=staging

  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://resume.ivanpetrov.com
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to production
        run: sam deploy --config-env production
      - name: Smoke test production
        run: |
          STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://resume.ivanpetrov.com)
          if [ "$STATUS" -ne 200 ]; then
            echo "Smoke test failed! Rolling back..."
            sam deploy --config-env production --resolve-s3 --previous
            exit 1
          fi

SAM config для environments

# samconfig.toml
[dev.deploy.parameters]
stack_name = "crc-dev"
s3_bucket = "crc-deploy-dev"
parameter_overrides = "Environment=dev"

[staging.deploy.parameters]
stack_name = "crc-staging"
s3_bucket = "crc-deploy-staging"
parameter_overrides = "Environment=staging"

[production.deploy.parameters]
stack_name = "crc-production"
s3_bucket = "crc-deploy-prod"
parameter_overrides = "Environment=production"
confirm_changeset = true

Architect Mod: Blueprint Drift

Задача

Обнаружение и предотвращение drift -- ситуации, когда реальная инфраструктура отличается от описания в коде.

Реализация: AWS Config + drift detection

# CloudFormation drift detection
aws cloudformation detect-stack-drift --stack-name crc-production

# Проверка результата
aws cloudformation describe-stack-drift-detection-status \
  --stack-drift-detection-id DRIFT_ID

# Automated drift check в CI/CD
# .github/workflows/drift-check.yml
name: Drift Detection

on:
  schedule:
    - cron: '0 9 * * 1'  # Every Monday at 9 AM

jobs:
  check-drift:
    runs-on: ubuntu-latest
    steps:
      - name: Detect drift
        run: |
          DRIFT_ID=$(aws cloudformation detect-stack-drift \
            --stack-name crc-production \
            --query 'StackDriftDetectionId' --output text)

          sleep 30  # Wait for detection

          STATUS=$(aws cloudformation describe-stack-drift-detection-status \
            --stack-drift-detection-id $DRIFT_ID \
            --query 'StackDriftStatus' --output text)

          if [ "$STATUS" != "IN_SYNC" ]; then
            echo "DRIFT DETECTED! Stack is $STATUS"
            # Send Slack/email notification
            exit 1
          fi

          echo "Stack is in sync"

Data Engineer Mod: Data Doesn't Deploy Itself

Задача

CI/CD для data pipelines: автоматическое обновление схем, миграции данных, тесты данных.

Реализация

# .github/workflows/data-pipeline.yml
name: Data Pipeline Deploy

on:
  push:
    paths: ['data/**']

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Validate schemas
        run: |
          python -c "
          import json
          with open('data/schema.json') as f:
              schema = json.load(f)
          assert 'id' in schema['properties']
          assert 'count' in schema['properties']
          print('Schema valid')
          "

  deploy-pipeline:
    needs: validate
    runs-on: ubuntu-latest
    steps:
      - name: Update Glue job
        run: |
          aws glue update-job --job-name crc-analytics \
            --job-update "$(cat data/glue-job-config.json)"

      - name: Run data quality checks
        run: |
          python data/quality_checks.py

AI Engineer Mod: Ship It

Задача

CI/CD для ML-моделей: версионирование промптов, A/B тестирование, мониторинг качества.

Версионирование промптов

# prompts/v1.py
SYSTEM_PROMPT = """You are a helpful assistant that answers questions
about Ivan Petrov's resume. Be concise, 2-3 sentences max."""

# prompts/v2.py (A/B test variant)
SYSTEM_PROMPT = """You are Ivan Petrov's AI assistant. Answer questions
about his skills and experience. Include specific examples when possible.
Limit to 3 sentences."""
# .github/workflows/ai-deploy.yml
name: AI Model Deploy

on:
  push:
    paths: ['prompts/**', 'ai/**']

jobs:
  test-prompts:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Test prompt quality
        run: |
          python ai/test_prompts.py
          # Tests: response length, relevance, safety

  deploy:
    needs: test-prompts
    runs-on: ubuntu-latest
    steps:
      - name: Deploy with A/B config
        run: |
          # 80% traffic to v1, 20% to v2
          aws lambda update-alias \
            --function-name ai-chat \
            --name live \
            --routing-config '{"AdditionalVersionWeights":{"2":0.2}}'

Проверь себя

Что такое event-driven архитектура в Developer Mod 'Chain Reaction'?

Зачем в multi-stage CI/CD нужен manual approval для production?

Зачем нужны data quality checks в Data Mod 'Data Doesn't Deploy Itself'?

Что такое A/B тестирование промптов в AI Mod 'Ship It'?

Что такое drift detection в контексте IaC?