Skip to content

gocroot/aws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deplong Golang CI/CD to Amazon Web Service

This is a simple Golang Model-Controller template using AWS Lambda Go and mongodb.com as the database host. It is compatible with AWS Lambda CI/CD deployment.

Start here: Just Fork this repo

MongoDB Preparation

The first thing to do is prepare a Mongo database using this template:

  1. Sign up for mongodb.com and create one instance of Data Services of mongodb.
  2. Download MongoDB Compass, connect with your mongo string URI from mongodb.com
  3. Create database name iteung and collection reply
    image
  4. Import this json into reply collection.
    image
    image
    image

Folder Structure

This boilerplate has several folders with different functions, such as:

  • .github: GitHub Action yml configuration.
  • config: all apps configuration like database, API, token.
  • controller: all of the endpoint functions
  • model: all of the type structs used in this app
  • helper: helper folder with list of function only called by others file

AWS Lambda CI/CD setup

Sign Up and login into aws console and go to AWS Lambda menu and follow this instruction:

  1. Klik Create Function and input Function name, select Amazon Linux 2023 Runtime, select x86_64 Architecture
    image
  2. In Advanced settings select Enable function URL, None Aut type. image
  3. Please set the environment variable in Configuration tab:
    image
    MONGOSTRING=YOURMONGOSTRINGACCESS
    WAQRKEYWORD=yourkeyword
    WEBHOOKURL=https://yourappname.alwaysdata.net/whatsauth/webhook
    WEBHOOKSECRET=yoursecret
    WAPHONENUMBER=62811111
  4. Go to the menu Identity and Access Management (IAM), set lambda:UpdateFunctionCode Policies, and add new users.
    image
  5. Create an access key from the Security credentials tab.
    image
  6. Go to settings>Secrets and variables>Actions in the GitHub repo. Add several Repository secrets.
    image

WhatsAuth Signup

  1. Go to the WhatsAuth signup page and scan with your WhatsApp camera menu for login.

  2. Input the webhook URL(https://yourappname.alwaysdata.net/whatsauth/webhook) and your secret from the WEBHOOKSECRET setting environment on Always Data.
    image

  3. Follow this instruction, in the end of the instruction you will get 30 days token using this request

  4. Save the token into MongoDB, open iteung db, create a profile collection and insert this JSON document with your 30-day token and your WhatsApp number.
    image
    image

    {
      "token":"v4.public.asoiduas",
      "phonenumber":"6281111"
    }

    image

Refresh Whatsapp API Token

To continue using the WhatsAuth service, we must get a new token every 3 weeks before the token expires in 30 days.

  1. Open Menu Amazon EventBridge> Buses > Rules > Create Rule. Choose like screenshot.
    image
  2. Input for every 20 days; next, choose lambda function then set ENable state. image
    image image
  3. Completing create schedule image

Upgrade Apps

If you want to upgrade apps, please delete (go.mod) and (go.sum) files first, then type the command in your terminal or cmd :

go mod init gocroot
go mod tidy

About

Deplong Golang CI/CD to AWS Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages