Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active August 26, 2022 21:05
Show Gist options
  • Save antklim/61b479501a7b13dc6fcf774daab2c233 to your computer and use it in GitHub Desktop.
Save antklim/61b479501a7b13dc6fcf774daab2c233 to your computer and use it in GitHub Desktop.
Distribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: !Sub ${ProjectName} project distribution
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
- OPTIONS
CachePolicyId: !Ref FrontendCachingPolicy
Compress: "true"
TargetOriginId: !Sub ${ProjectName}-frontend
ViewerProtocolPolicy: redirect-to-https
CacheBehaviors:
- AllowedMethods:
- GET
- HEAD
- OPTIONS
- PUT
- POST
- PATCH
- DELETE
CachedMethods:
- GET
- HEAD
- OPTIONS
# AWS provided CachingOptimized caching policy
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6
Compress: "true"
PathPattern: !Sub /${ApiResource}
TargetOriginId: !Sub ${ProjectName}-api
ViewerProtocolPolicy: redirect-to-https
DefaultRootObject: index.html
Enabled: !Ref DistributionEnabled
HttpVersion: http2
Origins:
# S3 Origin
- Id: !Sub ${ProjectName}-frontend
DomainName: !Sub
- ${Bucket}.s3.${AWS::Region}.amazonaws.com
- { Bucket: !Ref FrontendS3 }
S3OriginConfig:
OriginAccessIdentity: !Sub
- origin-access-identity/cloudfront/${OAI}
- { OAI: !Ref FrontendOAI }
# API Gateway origin
- Id: !Sub ${ProjectName}-api
DomainName: !Sub
- ${API}.execute-api.${AWS::Region}.amazonaws.com
- { API: !Ref APIGW }
OriginPath: !Sub /${StageName}
CustomOriginConfig:
OriginProtocolPolicy: https-only
OriginSSLProtocols:
- TLSv1
PriceClass: PriceClass_200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment