Blog 0.10: Using github Actions with AWS S3 Bucket
Github Action
In this blog, I will demonstrate some actions with Github Action script. Github Action allow us to automate, customize, and execute your software development workflows right in your repository with GitHub Actions.
With Github action we can create and share actions to perform any job including CI/CD (Continuous Integration and Continous Delivery). Furthermore, we can also completly customized the workflow.
Storing Secrets on Github Repo
We can store our credentials on github repository as secrets and use GitHub Action script to run specific jobs.
Storing Credentials on Github Repo
We need to store credentials insde the github repository. Go to Settings -> Secrets -> Add New Repository Secret
Creating Github Action Script
First, we need to create a directory named .github/workflows in the same directory. The directory name workflows inside the ‘.github’ should be plural.
The Script running the Github Action should be in the yaml format.
Following script will upload specified file to AWS S3 Bucket everytime when the action git push is performed. We can set the action to be different with specified jobs.
name: upload_file
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: $
aws-secret-access-key: $
aws-region: us-west-2
- name: copy files to s3 bucket
run: |
aws s3 cp testingFile.txt s3://myTestingBucket/testingFile.txt
Explanation on Script
- In the above script, we have used the latest ubuntu to run our script.
- Every time whenever the code is pushed into the Github Repository the script will run with the job(actions) specified
- By using the saved credentials on Github Repository we can get access to AWS S3 Bucket
- Credentials access: To use credentials we need to use ‘$’ sign.
- We need to use the SECRETS inside double brackets: secrets.AWS_ACCESS_KEY and secrets.AWS_SECRET_KEY
- Filename testingFile.txt will be copied into the S3 bucket myTestingBucket with name testingFile.txt