Aws cloudfront

From paulpas/agent-skill-router · View interactive version

Aws cloudfront is an AI agent skill from the GitHub repository paulpas/agent-skill-router. "Configures CloudFront CDN for global content distribution with edge caching" DDoS protection, and SSL/TLS termination for improved performance and security.

How to use this skill

Skill file

CloudFront (Amazon CloudFront)

Distribute content globally with edge caching, DDoS protection, and SSL/TLS termination for improved performance and security.

TL;DR Checklist


When to Use

Use CloudFront when:


Purpose and Use Cases

Primary Purpose: Cache and deliver content globally from edge locations with DDoS protection, SSL/TLS termination, and high performance.

Common Use Cases:

  1. Static Website — S3 origin with CloudFront CDN
  2. API Acceleration — CloudFront cache for API responses
  3. Video Streaming — Deliver video from edge locations
  4. DDoS Protection — AWS Shield Standard + WAF
  5. Application Acceleration — Reduce latency globally

Architecture Design Patterns

Pattern 1: S3 Static Website with CloudFront

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  # S3 Bucket for Website
  WebsiteBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub 'website-${AWS::AccountId}'
      VersioningConfiguration:
        Status: Enabled
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true
      Tags:
        - Key: Purpose
          Value: website-cdn

  # CloudFront Origin Access Identity
  OriginAccessIdentity:
    Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
    Properties:
      CloudFrontOriginAccessIdentityConfig:
        Comment: OAI for S3 website bucket

  # S3 Bucket Policy for CloudFront
  BucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref WebsiteBucket
      PolicyText:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Sub 'arn:aws:iam::cloudfront.amazonaws.com:user/CloudFront Origin Access Identity ${OriginAccessIdentity}'
            Action: s3:GetObject
            Resource: !Sub '${WebsiteBucket.Arn}/*'

  # CloudFront Distribution
  Distribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Enabled: true
        HttpVersion: http2and3
        DefaultRootObject: index.html
        Comment: CDN for website
        PriceClass: PriceClass_100  # US, Canada, Europe
        
        # Origin - S3 Bucket
        Origins:
          - Id: S3Origin
            DomainName: !GetAtt WebsiteBucket.RegionalDomainName
            S3OriginConfig:
              OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${OriginAccessIdentity}'
            OriginAccessControlId: !Ref OriginAccessControl
        
        # Default Cache Behavior
        DefaultCacheBehavior:
          AllowedMethods:
            - GET
            - HEAD
            - OPTIONS
          CachedMethods:
            - GET
            - HEAD
          TargetOriginId: S3Origin
          ViewerProtocolPolicy: redirect-to-https
          Compress: true
          
          # Cache Policy
          CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6  # Managed-CachingOptimized
          
          # Origin Request Policy
          OriginRequestPolicyId: 216adef5-5c7f-47e4-b989-5492eafa07d3  # Managed-CORS-S3Origin
        
        # Cache Behaviors for Different Content Types
        CacheBehaviors:
          # HTML with short TTL
          - PathPattern: '*.html'
            AllowedMethods:
              - GET
              - HEAD
            CachedMethods:
              - GET
              - HEAD
            TargetOriginId: S3Origin
            ViewerProtocolPolicy: redirect-to-https
            Compress: true
            CachePolicyId: 4135ea3d-c35d-46eb-81d7-reeSPECIFIC  # Managed-CachingDisabled for HTML
          
          # API Gateway Origin
          - PathPattern: '/api/*'
            AllowedMethods:
              - GET
              - HEAD
              - OPTIONS
              - PUT
              - POST
              - PATCH
              - DELETE
            CachedMethods:
              - GET
              - HEAD
            TargetOriginId: APIOrigin
            ViewerProtocolPolicy: https-only
            Compress: true
            CachePolicyId: 4135ea3d-c35d-46eb-81d7-reeSPECIFIC  # Managed-CachingDisabled
            OriginRequestPolicyId: b689b0a8-53d0-4196-a37e-61753b0d5ef7  # Managed-AllViewerAndWhitelistCloudFront
        
        # Restrictions
        Restrictions:
          GeoRestriction:
            RestrictionType: none
        
        # SSL Certificate
        ViewerCertificate:
          CloudFrontDefaultCertificate: true
        
        # CloudWatch Logging
        Logging:
          Bucket: !GetAtt LoggingBucket.DomainName
          Prefix: cloudfront-logs/
          IncludeCookies: false
      Tags:
        - Key: Purpose
          Value: website-cdn

  # Logging Bucket
  LoggingBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub 'cloudfront-logs-${AWS::AccountId}'
      AccessControl: LogDeliveryWrite
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true

  # Origin Access Control (newer than OAI)
  OriginAccessControl:
    Type: AWS::CloudFront::OriginAccessControl
    Properties:
      OriginAccessControlConfig:
        Name: S3OAC
        OriginAccessControlOriginType: s3
        SigningBehavior: always
        SigningProtocol: sigv4

  # CloudWatch Metrics
  CacheHitRateMetric:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: cloudfront-low-cache-hit-rate
      MetricName: CacheHitRate
      Namespace: AWS/CloudFront
      Statistic: Average
      Period: 3600
      EvaluationPeriods: 1
      Threshold: 50
      ComparisonOperator: LessThanThreshold
      Dimensions:
        - Name: DistributionId
          Value: !Ref Distribution

  # WAF Association
  DistributionWAF:
    Type: AWS::WAFv2::WebACL
    Properties:
      Scope: CLOUDFRONT
      DefaultAction:
        Allow: {}
      Rules:
        - Name: AWSManagedRulesCommonRuleSet
          Priority: 1
          OverrideAction:
            None: {}
          VisibilityConfig:
            SampledRequestsEnabled: true
            CloudWatchMetricsEnabled: true
            MetricName: AWSManagedRulesCommonRuleSetMetric
          Statement:
            ManagedRuleGroupStatement:
              VendorName: AWS
              Name: AWSManagedRulesCommonRuleSet
      VisibilityConfig:
        SampledRequestsEnabled: true
        CloudWatchMetricsEnabled: true
        MetricName: DistributionWAF

Outputs:
  DistributionDomainName:
    Value: !GetAtt Distribution.DomainName
    Description: CloudFront distribution domain name
  DistributionId:
    Value: !Ref Distribution
    Description: CloudFront distribution ID

Key Elements:


Integration Approaches

1. Integration with S3

CloudFront + S3 enables:

2. Integration with ALB/API Gateway

CloudFront + ALB provides:

3. Integration with ACM

ACM + CloudFront enables:

4. Integration with WAF

WAF + CloudFront provides:


Common Pitfalls

❌ Pitfall 1: Low Cache Hit Ratio

Problem: Most requests miss cache; high origin load.

Solution:

❌ Pitfall 2: Stale Content After Deploy

Problem: Users see old version after code deploy.

Solution:

❌ Pitfall 3: No Origin Failover

Problem: Origin down = CDN down (no cached fallback).

Solution:

❌ Pitfall 4: Slow Origin Causing Slowness

Problem: Even cached requests slow if origin slow.

Solution:

❌ Pitfall 5: No DDoS Protection

Problem: Large DDoS attacks overwhelm edge.

Solution:


Best Practices Summary

| Category | Best Practice |

|---|---|

| Caching | High TTL for static; low for dynamic |

| Hit Ratio | Monitor and optimize query strings |

| Invalidation | Versioned filenames; CI/CD automation |

| Security | WAF enabled; HTTPS only; OAI for S3 |

| Performance | Origin Shield; compression enabled |


Related Skills

| Skill | Purpose |

|---|---|

| cncf-aws-s3 | Origin bucket for static content |

| cncf-aws-route53 | DNS alias to CloudFront |

| cncf-aws-acm | SSL/TLS certificates |


Core Workflow

  1. Assess Requirements — Understand the use case, scale, integration needs, and existing infrastructure. Checkpoint: Document requirements, constraints, and success criteria.
  1. Design Architecture — Plan component interactions, data flow, and deployment strategy using cloud-native best practices. Checkpoint: Verify the architecture addresses all requirements and follows CNCF conventions.
  1. Implement & Configure — Create manifests, configurations, and deployment scripts. Include resource limits, health checks, and observability hooks. Checkpoint: Validate all YAML against schema and test in a staging environment.
  1. Deploy & Monitor — Apply manifests to the cluster, verify component health, and confirm observability is working. Checkpoint: Confirm all pods/services are running, probes passing, and metrics/alerts configured.

Constraints

MUST DO

MUST NOT DO

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.