September 7, 2026 · Varun Sharma

Automate GitHub Actions: Zip and Deploy to AWS Elastic Beanstalk

Manually zipping your project files and uploading them to the AWS console is a massive bottleneck. When you are ready to push code to production, you want that process to be automated, fast, and secure.

This guide will show you how to set up a GitHub Actions workflow that triggers whenever you push to your production branch. The workflow will automatically install your dependencies, build your production assets, package the build folder into a ZIP file, and deploy it straight to AWS Elastic Beanstalk.

Prerequisites

Before diving into the code, ensure you have the following ready:

  • An AWS Elastic Beanstalk Application and Environment already set up.

  • An IAM User with programmatic access keys (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) and permissions to deploy to Elastic Beanstalk (like AWSElasticBeanstalkWebTier or custom deployment policies).

  • A GitHub Repository housing your application code.

Step 1: Add AWS Secrets to GitHub

Never hardcode your AWS credentials into your codebase. We need to store them securely in GitHub Secrets.

  1. Navigate to your GitHub repository.

  2. Go to Settings > Secrets and variables > Actions.

  3. Click New repository secret and add the following four secrets:

    • AWS_ACCESS_KEY_ID: Your IAM user access key.

    • AWS_SECRET_ACCESS_KEY: Your IAM user secret key.

    • AWS_REGION: The AWS region where your environment is hosted (e.g., us-east-1).

    • AWS_APPLICATION_NAME: The exact name of your Elastic Beanstalk Application.

Step 2: Create the GitHub Actions Workflow File

GitHub Actions looks for workflow definitions inside a specific directory. In the root of your project, create the following path: .github/workflows/deploy.yml.

Paste the following configuration into your deploy.yml file:

yaml

name: Deploy to Elastic Beanstalk

on:
  push:
    branches:
      - production # Triggers the workflow only on pushes to the production branch

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      # Step 1: Check out the repository source code
      - name: Checkout Source Code
        uses: actions/checkout@v4

      # Step 2: Set up Node.js environment (Adjust version and language as needed)
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20' 
          cache: 'npm'

      # Step 3: Install dependencies and compile the custom build folder
      - name: Install Dependencies & Build
        run: |
          npm ci
          npm run build

      # Step 4: Generate a unique timestamp for the deployment artifact package
      - name: Generate Deployment Version Tag
        id: version
        run: echo "VERSION=deploy-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

      # Step 5: Zip only the specific build files required for production
      # Note: Include your build output folder (e.g., 'dist' or 'build') and configuration files like 'package.json'
      - name: Create Custom Deployment ZIP Package
        run: |
          zip -r ${{ env.VERSION }}.zip dist package.json package-lock.json

      # Step 6: Configure your AWS credentials using GitHub Secrets
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

      # Step 7: Upload the zip artifact directly to Elastic Beanstalk
      - name: Deploy to AWS Elastic Beanstalk
        uses: einaregilsson/beanstalk-deploy@v22
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          application_name: ${{ secrets.AWS_APPLICATION_NAME }}
          environment_name: 'Your-Actual-EB-Environment-Name' # Replace with your target EB environment name
          version_label: ${{ env.VERSION }}
          region: ${{ secrets.AWS_REGION }}
          deployment_package: ${{ env.VERSION }}.zip

Use code with caution.

Workflow Breakdown: How it Works

  • The Trigger (on: push): The workflow remains idle until a merge or direct push happens on the production branch.

  • The Custom Zip (Step 5): Instead of zipping your entire repository (which includes bulky development files and documentation), the zip -r command targets only the compiled production code (dist) and the package manifest files required by Elastic Beanstalk to run your app server.

  • The Deployment (Step 7): We use the highly trusted einaregilsson/beanstalk-deploy action. It takes your generated ZIP package, pushes it to an AWS S3 bucket managed by Beanstalk under the hood, creates a new Application Version, and instructs your environment to execute a rolling update.

Step 3: Push and Test Your Automation

Commit your changes, push the workflow file to your repository, and merge it into your production branch.

To track its progress:

  1. Click the Actions tab in your GitHub repository.

  2. Select your Deploy to Elastic Beanstalk workflow.

  3. Watch the logs update live. If everything turns green, open your AWS Elastic Beanstalk dashboard to see your new application version gracefully spinning up!

Share:

Comments

Join the discussion and share your thoughts.

Leave a comment