CI/CD pipeline for AWS Lambda using GitHub

Vineet k
3 min readJan 20, 2021

--

Create CI/CD pipeline for AWS Lambda Server-less using github workflow.

First create aws lambda function using https://www.npmjs.com/package/serverless which i have shown in one of my blog post.

Now create git private repository as you don’t want your aws secrets to be public.

Configure your AWS secrets as shown below.

Now go to actions to set up workflow yourself as show below.

Use the below main.yaml file as show below

main.yaml is given below

##############################

name: deploy to lambda

on: [push]

jobs:

deploy_source:

name: build and deploy lambda

strategy:

matrix:

node-version: [12.x]

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node-version }}

uses: actions/setup-node@v1

with:

node-version: ${{ matrix.node-version }}

- name: npm install and build

run: |

npm ci

npm run build — if-present

env:

CI: true

- name: zip

uses: montudor/action-zip@v0.1.0

with:

args: zip -qq -r ./bundle.zip ./

- name: default deploy

uses: appleboy/lambda-action@master

with:

aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}

aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

aws_region: us-east-1

function_name: hello-world-medium-dev-hello

zip_file: bundle.zip

############################################

Now in above main.yaml file don’t forget to change the function name to your aws lambda function which you want to use.

Now when you make changes to your lambda code locally in may be visual studio and commit the same in git,workflow will automatically get’s triggered as shown below

And if everything is perfect you will get successfully deployed code in aws lambda.

Note: Also don’t forget to commit package-lock.json and don’t commit node_modules.

--

--