Skip to content

Commit

Permalink
Add cloudfront distributiom
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Feb 19, 2024
1 parent 66a5276 commit f02ebbe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 83 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/deploy-frontend-dev.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: DeployFrontendServerlessDev

on:
workflow_run:
workflows: ["DeployBackendDev"]
types:
- completed
branches:
- "master"
push

jobs:
deploy-frontend-dev:
Expand Down Expand Up @@ -52,5 +47,4 @@ jobs:
no-fail-on-empty-changeset: "1"
parameter-overrides: >-
EnvName=dev,
ZipFileName=canopas_website_SSR_dev_${{ github.sha }}-${{ github.run_attempt }}.zip,
CloudfrontURL=${{ secrets.CLOUDFRONT_URL_VALUE_DEV }}
ZipFileName=canopas_website_SSR_dev_${{ github.sha }}-${{ github.run_attempt }}.zip
140 changes: 65 additions & 75 deletions infrastructure/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,10 @@ Parameters:
ZipFileName:
Type: String
Description: Name of the zip file.
CloudfrontURL:
Type: String
Description: Cloudfront URL.

Resources:
HttpApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: $default
Description:
Fn::Sub: Canopas Website SSR Frontend API ${EnvName}
DefinitionBody:
openapi: "3.0.1"
info:
title:
Fn::Sub: canopas-website-ssr-frontend-${EnvName}
version: "1.0"
paths:
/favicon.ico:
x-amazon-apigateway-any-method:
responses:
default:
description: "Default response for ANY /favicon.ico"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::Sub: "${CloudfrontURL}favicon.ico"
connectionType: "INTERNET"
/sitemap.xml:
x-amazon-apigateway-any-method:
responses:
default:
description: "Default response for ANY /sitemap.xml"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::Sub: "${CloudfrontURL}sitemap.xml"
connectionType: "INTERNET"
/robots.txt:
x-amazon-apigateway-any-method:
responses:
default:
description: "Default response for ANY /robots.txt"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::Sub: "${CloudfrontURL}robots.txt"
connectionType: "INTERNET"
/apple-touch-icon.png:
x-amazon-apigateway-any-method:
responses:
default:
description: "Default response for ANY /apple-touch-icon.png"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::Sub: "${CloudfrontURL}apple-touch-icon.png"
connectionType: "INTERNET"
x-amazon-apigateway-importexport-version: "1.0"

HttpApiFunction:
Resources:
SSRFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Zip
Expand All @@ -101,11 +36,66 @@ Resources:
Fn::Sub: canopas-website-ssr-frontend-${EnvName}
Description:
Fn::Sub: Canopas Website SSR Frontend Lambda ${EnvName}
Events:
ProxyResource:
Type: HttpApi
Properties:
ApiId:
Ref: HttpApi
Path: $default
Method: any
FunctionUrlConfig:
AuthType: NONE

CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
PriceClass: PriceClass_All
HttpVersion: http2
IPV6Enabled: true
Comment: Distribution with SSR Lambda Function URL
Origins:
- DomainName:
Fn::Select: [2,
Fn::Split: [ "/",
Fn::GetAtt: SSRFunctionUrl.FunctionUrl ]]
Id: SSRLambda
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: match-viewer
- DomainName: canopas-website-ssr-dev.s3.ap-south-1.amazonaws.com
Id: StaticS3
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: match-viewer
Enabled: 'true'
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: SSRLambda
ViewerProtocolPolicy: redirect-to-https
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac
CacheBehaviors:
- PathPattern: /_nuxt/*
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6
OriginRequestPolicyId: 88a5eaf4-2fd4-4709-b370-b4c650ea3fcf
ResponseHeaderPolicyId: 5cc3b908-e619-4b99-88e5-2cf7f45965bd
TargetOriginId:
Ref: StaticS3
ViewerProtocolPolicy: redirect-to-https
- PathPattern: /sitemap.xml
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6
OriginRequestPolicyId: 88a5eaf4-2fd4-4709-b370-b4c650ea3fcf
ResponseHeaderPolicyId: 5cc3b908-e619-4b99-88e5-2cf7f45965bd
TargetOriginId:
Ref: StaticS3
ViewerProtocolPolicy: redirect-to-https



0 comments on commit f02ebbe

Please sign in to comment.