Day 86 - Project-7

Day 86 - Project-7

Project Description

  • The project involves deploying a Portfolio app on AWS S3 using GitHub Actions. Git Hub actions allows you to perform CICD with GitHub Repository integrated.

Pre-requisites

  1. Create an EC2 instance.

  2. Create an S3 bucket.

  3. Create an IAM user with the required permissions.

Project Steps

  • Get a Portfolio application from GitHub and fork it into your repository.

  • Get the portfolio code from your GitHub and clone it to your local machine or AWS server.

  • Now navigate to your AWS Management Console and create an IAM user for AWS CLI and security credentials.

  • Now create an S3 bucket that should be publicly accessible and enable static website hosting in properties.

  • Now go to your portfolio repository, click on settings, scroll down to Secrets and variables, click on it, and select Action. Click on New repository secret, write your secret name as AWS_ACCESS_KEY_ID, paste the access key ID, and click on Add security. Do the same for AWS_SECRET_ACCESS_KEY as well.

  • Now go to Actions on your repository, click on New workflow, and select "set up a workflow yourself." In that YAML file, copy this code and click on Commit changes.

 name: My-portfolio-website

 on:
   push:
     branches:
     - main

 jobs:
   build-and-deploy:
     runs-on: ubuntu-latest
     steps:
     - name: Checkout
       uses: actions/checkout@v1

     - name: Configure AWS Credentials
       uses: aws-actions/configure-aws-credentials@v1
       with:
         aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # This name should be same in your Repository secerts
         aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # This name should be same in your Repository secerts
         aws-region: us-east-1

     - name: Deploy static site to S3 bucket
       run: aws s3 sync . s3://<your bucket name> --delete

  • Now go to the S3 bucket and refresh it. Your files will be shown in the bucket.

  • Now add this below permission to your bucket policy in the permission section.
{

"Version": "2012-10-17",
"Statement": [
{

"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3 ::: <ypur bucket name>/*"

}

]

}

  • Now access your S3 bucket's static website host, and your website will be active.


Happy Learning

Thanks For Reading! :)

-DevOpsParthu💝💥