Host A Static Website with CI/CD Pipeline,s3,cloudfront

Nipulpatel
6 min readSep 29, 2023

--

Amazon S3:Amazon Simple Storage Service, is a highly scalable and popular cloud storage solution offered by Amazon Web Services (AWS), widely used for storing and retrieving data on the internet.

GitHub: GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.collaborative development and project hosting service. With the help of GitHub, an unlimited number of programmers from anywhere in the world can work on the same project. GitHub has a git version control (management) system that allows you to view and control any code changes by any developer and return to the state before the changes.In general, GitHub is a social network for developers where you can find open-source projects from other developers, practice coding, and store your portfolio.

Continuous Integration(CI)

When We talk about software integration, it may not be necessary for stable projects, but it is essential for projects with frequent changes. After all, waiting to integrate results often leads to integration conflicts and can take too long to resolve, leading to project delays.

Continuous Delivery(CD)

Continuous delivery (CD) picks up where continuous integration is over. While CI is the process to build and test automatically, CD deploys all code changes to the testing or staging environment in the build.

CloudFront:Cloudfront is an AWS content delivery network that provides the ability to cache content at “edge” locations across the globe for faster load and response times for your application. It helps reduce latency to your application and also reduces the load on compute resources by providing commonly used files or content from the cached edge location.

we create:

  1. Create a GitHub repository.
  2. Create a S3 bucket.
  3. Create a CI/CD Pipeline.
  4. Deploy the Pipeline and verify that you can reach your static website. Make an update to the code in GitHub and verify the change in your static website.
  5. Add CloudFront as a CDN for your static website.

Part I: Create a new GitHub repository

  1. create a new repository ,,Click Create a new repository button and give it a name. I am going to name it as pipeline-s3. Add a README file and then click Create repository button.

2. Add file by clicking Upload files option and add your static website file.

3. Click Commit changes button.

Part 2: Create and configure an S3 bucket to deploy your GitHub files.

  1. Go to S3>Create bucket and name your bucket.

2. Uncheck Block all public access and acknowledge. Keep the default settings and click Create button.

3. Go to Properties tab and scroll all the way to the bottom to Edit static website hosting section. Enable Static website hosting and choose Host a static website as Hosting type. Enter the Index document name and then click Save changes button.

4. Go to Permissions tab>Edit bucket policy. Paste below bucket policy and then click Save changes button. Make sure you update the “Resource”:”arn: your arn/*” with your s3 bucket arn and add /* so that you add all files within your bucket.

Part 3: Create CodePipeline

  1. Go to CodePipeline>Create pipeline>Name your Pipeline>Choose New service role> Click Next button.

2. Select GitHub (Version 2) as Source provider.

3. Click Connect to GitHub button.

4. Give it a name. Click Connect to GitHub button.

5. Click Install a new app button.

6. Select Only select repositories and select your new repository. Click Save button.

7. Click Connect button.

8. Give your Repository Name and select Branch name and click Next.

9. Click Skip build stage.

10. Add deploy stage as Amazon S3. Choose the Region your S3 bucket was created in and then select the S3 bucket you just created for your Resume project. Make sure select Extract file before deploy because Codepipleline compress the artifact.

11. Review and then click Create pipeline. Now you have deployed your pipeline successfully.

Part 4: Testing

  1. Go to S3>Your bucket and confirm if you have README.md and storage.html file.

2. Click Properties and scroll to the bottom and copy the Bucket website endpoint address and paste in in the web browser.

We have access to the webpage.

3. Go to Github repository and edit the file. I added feature

Click commit changes.

Now refresh the webpage. Yes, the changes have been made. This is the power of CodePipeline!

Add CloudFront as a CDN for your static website.

1 Go to CloudFront>Create distribution>Choose the Amazon S3 bucket you just created

2. Keep the default settings and click Create Distribution.

3. Open the CloudFront Distribution you just created and click General tab and copy the Distribution domain name.

4.Paste the address and add your file name as shown below.

https://dz9j01roue8qu.cloudfront.net/storage.html

thank you happy learning!!!!

--

--

Responses (1)