From f02ebbe3898b2070678014e6ec152a073d511024 Mon Sep 17 00:00:00 2001 From: Sumita Canopas Date: Mon, 19 Feb 2024 12:24:34 +0530 Subject: [PATCH] Add cloudfront distributiom --- .github/workflows/deploy-frontend-dev.yml | 10 +- infrastructure/frontend.yml | 140 ++++++++++------------ 2 files changed, 67 insertions(+), 83 deletions(-) diff --git a/.github/workflows/deploy-frontend-dev.yml b/.github/workflows/deploy-frontend-dev.yml index 682acd5bd..3bb1b6c89 100644 --- a/.github/workflows/deploy-frontend-dev.yml +++ b/.github/workflows/deploy-frontend-dev.yml @@ -1,12 +1,7 @@ name: DeployFrontendServerlessDev on: - workflow_run: - workflows: ["DeployBackendDev"] - types: - - completed - branches: - - "master" + push jobs: deploy-frontend-dev: @@ -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 \ No newline at end of file diff --git a/infrastructure/frontend.yml b/infrastructure/frontend.yml index 0b242e023..c4022520a 100644 --- a/infrastructure/frontend.yml +++ b/infrastructure/frontend.yml @@ -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 @@ -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 + + + \ No newline at end of file