Deploy Code to S3 using github Action pipeline with Cloudformation validation
Contents
Deploy Code to S3 using github Action pipeline with Cloudformation validation 🪂 🚀 🛺
➤ First we need to create repo on Github.
➤ After creating repo go to that repo and create 5 Secrets for this pipeline.
➤ for creating secrets go to settings > Secrets and variables .
➤ click on New repository secret.
AWS_ACCESS_KEY_ID
AWS_CLOUDFRONT_DISTRIBUTION_ID
AWS_REGION
AWS_SECRET_ACCESS_KEY
S3_BUCKET
➤ these are the secrets we need to create, along with them values.
➤ after creating the Secrets push your code to repo along with ./github/workflows/pipeline.yml file.
➤ this file should have below content.
name: Deploy to S3
on:
push:
branches:
- main # Deploy when pushing to the main branch
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Sync files to S3
run: |
aws s3 sync . s3://${{ secrets.S3_BUCKET }} --delete
- name: Invalidate CloudFront
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"
➤ Or you should follow below git hub link.Access the GitHub repo here
➤ this pipeline deploy code to S3 bucket , and auto validate on Cloudfront distribution.