Quick setup on setting up a simple CI/CD workflow.
- AWS
- NodeJs
- Serverless
- GitHub Actions
- root > .github > .workflows
- .workflows > main.yml
npm i -g serverless
serverless create --template aws-nodejs
- IAMUserFullAccess,
- LambdaFullAccess
Make sure to save your access key and secret access key.
Assign the user's key-pair value secrets from AWS IAM User (post-creation).
Copy this code below and paste it inside the main.yml file
name: Deploy Lambda Action Fun
on:
push:
branches:
- master
jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: serverless deploy
uses: serverless/github-action@v3.1
with:
args: deploy
env:
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
# or if using AWS credentials directly
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
once this is pushed to master, github actions will automatically detect these access key and secret key. Then, run serverless deoloy behind the scenes for us. And that will deploy our lambda function to the AWS cloud.