Skip to content

Latest commit

 

History

History
118 lines (86 loc) · 2.89 KB

README.md

File metadata and controls

118 lines (86 loc) · 2.89 KB
title keywords description
AWS Elastic Beanstalk
aws
elastic beanstalk
deploy
amazon
aws-eb
Deploying to AWS Elastic Beanstalk.

AWS Elastic Beanstalk Example

Github StackBlitz

This example demonstrates how to deploy a Go Fiber application to AWS Elastic Beanstalk.

Description

This project provides a starting point for deploying a Go Fiber application to AWS Elastic Beanstalk. It includes necessary configuration files and scripts to build and deploy the application.

Requirements

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/aws-eb
  2. Initialize Elastic Beanstalk:

    eb init
  3. Create an Elastic Beanstalk environment:

    eb create
  4. Deploy the application:

    eb deploy

Build Process

The build process is defined in the Buildfile and build.sh scripts.

  • Buildfile:

    make: ./build.sh
  • build.sh:

    #!/bin/bash -xe
    # Get dependencies
    go get -u github.com/gofiber/fiber/v2
    
    # Build the binary
    go build -o application application.go
    
    # Modify permissions to make the binary executable.
    chmod +x application

Application Code

The main application code is in application.go:

package main

import (
    "log"
    "os"

    "github.com/gofiber/fiber/v2"
)

func main() {
    // Initialize the application
    app := fiber.New()

    // Hello, World!
    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

    // Listen and Serve on 0.0.0.0:$PORT
    port := os.Getenv("PORT")
    if port == "" {
        port = "5000"
    }

    log.Fatal(app.Listen(":" + port))
}

.gitignore

The .gitignore file includes configurations to ignore Elastic Beanstalk specific files:

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

Conclusion

This example provides a basic setup for deploying a Go Fiber application to AWS Elastic Beanstalk. It can be extended and customized further to fit the needs of more complex applications.

References