Now that you have written your serverless functions it’s time to deploy them in AWS Lamda which uses CloudFormation template to update itself
We are not going to do any rocket science here, all we are gonna do is to execute the manual step that you perform in console for deployment, i.e
>> serverless deploy
Let’s get started 🚀
- We need to define the yml file first that GitHub executes in actions, folder structure is as follows
|-.github/
|--workflow/
|---master.yml
- Now in that file copy/paste the code below,
name: Deploy Master
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
ref: master
- uses: actions/setup-node@master
with:
node-version: "16.14.2"
- name: Install Serverless Framework
run: npm install -g serverless
- name: Serverless AWS authentication
run: sls config credentials --provider aws --key ${{ secrets.AWS_ACCESS_KEY }} --secret ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Install dependencies
run: npm install --force
- name: Deploy
run: sls deploy -s dev --region us-east-1 #<-- change region here
- Now we need to add AWS credentials in Github secrets, go to settings -> secrets -> actions
- Now add your AWS credentials as `AWS_ACCESS_KEY` && `AWS_SECRET_ACCESS_KEY`, check here to how create one
- this is how it looks in Github:
With all the work done above we are good for our first deployment, note: this will deploy/update serverless in us-east-1 region, change region if needed
Now push the code to Github, and voilla 🎉