Skip to content

GitHub Actions: Deploy Laravel API to AWS Lambda

This workflow automates the deployment of a Laravel API to AWS Lambda using the Serverless Framework. It installs necessary dependencies, sets up PHP, and runs serverless deploy to push the application to AWS Lambda.

name: Deploy Laravel API to AWS Lambda
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install
- name: Install Serverless Framework
run: npm install -g serverless
- name: Deploy to Lambda
run: serverless deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: <your_best_region>

Requirements

  • AWS Credentials: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set as GitHub Secrets.
  • Serverless Framework: Installed in the workflow using npm install -g serverless.
  • Ensure you have created serverless.yml in the Laravel project. Bref: Serverless Laravel - Getting started.
  • Using shivammathur/setup-php to setup PHP in workflow.
  • Composer for installing Laravel dependencies.