Skip to content
Home » Insights » Deploying AWS Lambda with GitHub Actions

Deploying AWS Lambda with GitHub Actions

GitHub Actions is a powerful way to automate your projects. In this guide, we’ll show you how to deploy a simple Node.js application to AWS Lambda using GitHub Actions.

Creating an AWS Lambda Function

Firstly, go to the AWS Management Console and navigate to the Lambda service. Create a new function, specifying its name and functionality. Next, create an IAM role for the function, ensuring it includes the necessary permissions for Lambda function access.

GitHub Actions YAML File

Create a .github/workflows folder in your project directory and add a YAML file like the one below.

name: deploy to lambda

on:
  push

jobs:
  deploy_lambda:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
      - name: aws configure
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      - name: npm install
        run: | 
          npm i -g bestzip
          npm i
      - name: deploy
        run: | 
          bestzip bundle.zip *
          aws lambda update-function-code --function-name=my-lambda-function --zip-file=fileb://bundle.zip

This YAML file will run every time a push to the main branch occurs and contains the necessary steps to deploy a Node.js project to AWS Lambda.

GitHub Secrets Configuration

Navigate to the Settings tab in your GitHub repository, then go to the Secrets section. Add a new secret, defining the AWS Lambda access keys (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).

Now, with each push, GitHub Actions will automatically deploy your Node.js application to AWS Lambda. By following these steps, you can streamline the process and easily manage your application.