AWS Service Used: IAM, S3
Github Actions
Before jumping into automating the build.
AWS Service: IAM
1. Sign in as root user
2. Go to IAM service
Create a user with Programatic Access as password
Assign user S3FullAccess permission
Create User
Access key and secret will be available once the user is created. Please copy the both the credentials
AWS Service: S3
1. Sign in as same IAM user you just created
2. Go to S3 service
Create a new bucket, named as “github-action-workflow”
Properties > Static website hosting, add main page of the website
Permissions > Remove “block public access”
Permissions > Edit Policy
Add new statement : S3
Add action : GetObject
Add resource : arn:aws:s3:::github-action-workflow/*
3. Create Bucket
Github Actions
1. Create a new repository, say “githubDemoActions”
2. Go to Settings page > Secrets > Actions
3. Add the secret credentials that you got when a user was created in IAM service
Name: AWS_S3_BUCKET
Value: github-action-workflow
Name: AWS_ACCESS_ID
Value: Paste the access key id that was created at the time of user creation
Name: AWS_SECRET_ACCESS_KEY
Value: Paste the secret value that was created at the time of user creation
4. Clone the repository to your local system
5. Add a sample file, say index.html
6. Create .github/workflows folder under your local repository
7. Add app.yaml under workflows directory. Paste the given code
name: Github Workflow Demo
on:
push:
branches:
- master
jobs:
deploy:
name: Github Workflow actions
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-s3-bucket: ${{ secrets.AWS_S3_BUCKET }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Deploy to AWS S3
run: aws s3 sync . s3://github-action-workflow
8. Now you can check under Actions > Workflow
9. The project is now upload to AWS S3
10. Copy the index.html link from object property, the link is public now ✨