Member-only story

GitHub Action to update function code on AWS Lambda

Himanshu Singh
5 min readOct 3, 2024

--

A few weeks back I wrote a blog on how to write a Lambda function and access RDS and S3 in it, and how to use Eventbridge to create a scheduler to invoke the lambda function.

In that blog, I mentioned that my senior also asked me to push all the lambda code on GitHub and write a GitHub action to push the changes to lambda on AWS, so we won’t open AWS to make any changes to the code itself.

However, I did not mention how I wrote that action in that blog, so I decided to write a separate blog to add that missing part.

Let’s begin!

The blog I have mentioned above — https://hsnice16.medium.com/lambda-function-to-access-rds-s3-and-eventbridge-in-aws-f55b95e7a5bc

GitHub Action

The first thing that you will find in many GitHub actions is a name that one gives to the action itself. You will see this same name in the Actions tab, which you can find after the Pull requests tab.

Here’s how you can give a name

name: ƛ Push Code to Lambda

After giving a name, the next thing you will find in a GitHub action is the event on which we have to run this action.

In my case, I wanted to run this action when someone pushes some code to the main branch. So, I gave it like this -

on:
push:
branches:
— main

Now, we have to mention the actual job that this action has to do and the steps that the action will be taking in that job.

To do that, first, you will give a name to the job, and we will give the type of machine on which, we want to run this job.

You can do that using the below code

jobs:
update-lambda:
runs-on: ubuntu-latest

It’s time to put down the steps that this action should take.

First, we will start by checking out our code and setting up the Node.js

  steps:
- name: ⬇️ Checkout code
uses: actions/checkout@v3

- name: ⚙️ Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"

--

--

Himanshu Singh
Himanshu Singh

Written by Himanshu Singh

I write blogs around React JS, JavaScript, Web Dev, and Programming. Follow to read blogs around them.

No responses yet

Write a response