Skip to content

Instantly share code, notes, and snippets.

@paulswail
Last active November 11, 2022 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulswail/c04f471bddc276844dea85735f378813 to your computer and use it in GitHub Desktop.
Save paulswail/c04f471bddc276844dea85735f378813 to your computer and use it in GitHub Desktop.
Configuring a CloudFront distribution in front of API Gateway (Serverless Framework)
resources:
Resources:
APIGatewayFront:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Enabled: true
IPV6Enabled: true
HttpVersion: http2
Comment: CDN in front of API Gateway
Origins:
- Id: APIGWOrigin
DomainName: ${ApiId}.execute-api.${aws:region}.amazonaws.com # TODO fix this to properly reference API ID of API Gateway in same service
OriginPath: "/"
CustomOriginConfig:
HTTPSPort: 443
OriginProtocolPolicy: https-only
DefaultCacheBehavior:
AllowedMethods: ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
CachedMethods: ["GET", "HEAD", "OPTIONS"]
ForwardedValues:
Headers:
- Access-Control-Request-Headers
- Access-Control-Request-Method
- Origin
- Authorization
QueryString: true
TargetOriginId: APIGWOrigin
ViewerProtocolPolicy: https-only
Compress: true
DefaultTTL: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment