Skip to content

Static web hosting on aws cloudfront edge, secured with waf. CI CD pipeline on infrastructure code, and client side application

Notifications You must be signed in to change notification settings

edo92/Aws-Static-Website-CI-CD

Repository files navigation

Aws Static Website CI/CD


Static website hosting infrastructure on AWS by CDK. Deploys react source code to S3, serves website with low latency content delivery network with an origin access identity and Lambda@Edge. Secured by HTTPS (SSL/TLS) with certificate manager(ACM), and attaches it to the CloudFront distribution. Also secures cloudFront distribution with web application firewall (WAF) from common web-based attacks. This solution also includes two pipelines, one for cdk code infrastructue, and one for react codebase.


example workflow


Resources


🔑   Github Oauth Token

Create secret manager for github token

   aws secretsmanager create-secret --name demoapp/gitSourcetoken --secret-string <GITHUB_TOKEN>

Or

   aws secretsmanager update-secret --secret-id demoapp/gitSourcetoken --secret-string <GITHUB_TOKEN>

📜   Aws Credentials

Export local environmental variables

   export AWS_ACCESS_KEY_ID=<XXXX>
   export AWS_SECRET_ACCESS_KEY=<XXXX>
   export AWS_DEFAULT_REGION=<XXXX>

⚙️   Configuration

Configure credentials in config.json

    "settings": {
      "locations": ["US"],
      "region": "<Region for distribution>",
      "domainName": "<Url link route53>",
      "hostedZoneId": "<Host zone id form route53>"
    },

    // React app source code
   "project_source": {
      "branch": "main",
      "owner": "<OWNER>",
      "repo": "<REPO>",
      "secretToken": "<setup in next step>",
    },

    // Cdk infrastructure code
   "cdk_source": {
      "branch": "main",
      "owner": "<OWNER>",
      "repo": "<REPO>",
      "secretToken": "<setup in next step>",
    }

🔨   Get Started

  • Install
   npm install
  • deploy
   cdk deploy


⚠️   Issues


Initial deployment

  On Initial Deployment: Cdk pipeline will fail to prevent repeate deployment


Import alias path not found

   alias cdk="npx aws-cdk"

Distribution deletion stuck in progress

   aws cloudfront get-distribution-config --id ${id} | jq '. | .DistributionConfig' > /tmp/disable-distribution-${id}

Or

   aws cloudfront delete-distribution --id ${id} --if-match \
   $(aws cloudfront get-distribution-config --id ${id} | jq .ETag -r)

About

Static web hosting on aws cloudfront edge, secured with waf. CI CD pipeline on infrastructure code, and client side application

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published