Deployment of Go App on AWS EC2

Hello Guys , Good Evening . Recently I come across one issue while deploying my Go app onto Amazon Web Services EC2. Actually in my demo project, I have used https://github.com/magiconair/properties for reading the values from properties file.
Kindly take a note

GoProject/src/MindBowser/MBIS
     |------------> resources
                           |----------> Exception.properties
     |------------->utils
                           |----------> ResourceManager.go
     |------------->constants
                          |------------> DemoConstant.go
     |------------------------------> main.go

   ( Here I've not given the complete structure )

    Exception.properties
    --------------------
               exception.message.could.not.login=Could not log you in.
               exception.message.email.not.registered=Email id not registered.    

    DemoConstant.go
    ---------------
               package constants
               var COULD_NOT_LOGIN        = "exception.message.could.not.login"
               var EMAIL_NOT_REGISTERED   = "exception.message.email.not.registered" 

     ResourceManager.go
     ------------------
               package utils
               import (
                      "github.com/magiconair/properties"
                )

                var PropertyFile = []string{"${HOME}/GoProject/src/MindBowser/MBIS/resources/exception.properties"}

                var Props, _ = properties.LoadFiles(PropertyFile, properties.UTF8, true)

                 type ResourceManager struct {
                  }

                 func (res ResourceManager) GetProperty(strs string) string {

                 message := ""
                 var ok bool
                  message, ok = Props.Get(strs)
                  if !ok {
	                 return Props.MustGet("not.found")
                   } else {
	               return message
                   }
                 }  

       main.go
       -----------
                 package main
                  import  (
                           "fmt"
                           "MindBowser/MBIS/resources"
                           "MindBowser/MBIS/utils"
                            "MindBowser/MBIS/constants"
                    )
                   var resourceManager *utils.ResourceManager = &utils.ResourceManager{}
                   func main(){
                    fmt.Println(resourceManager.GetProperty(constants.COULD_NOT_LOGIN))
                    fmt.Println(resourceManager.GetProperty(constants.EMAIL_NOT_REGISTERED))

                   /* In above lines I'm just printing the exception messages */
                 }

So its working is simple and this one is the RESTful Web App and I haven’t included WebService and other layers.

So this demo project is working locally on Ubuntu OS. But after deploying it to AWS EC2, I’m getting the Error

The above code is completely fine and its working locally.

MB@MB-VirtualBox:~/GoProject/src/MindBowser/MBIS/main <-----Here I’m creating binary file which I’m trying to deploy. while executing this errors are coming.

Kindly try to suggest the solution on top priority basis.

Hello guys , does anybody knows why this error is coming ? If needed anything, let me know .

Just a gues, but the error is there because the file is not.

Make sure that the file /root/GoProject/src/MindBrowser/MBIS/resources/exception.properties exist and is readable for the user that runs the program.

Also given the code you’ve shown to us, it seems as if it is running as root. I’d try to avoid that unless necessary.

Hi Mr. Nobbz, Thanks for your reply. When I’m running it locally it is working fine but when trying to run on EC2 it showing that error. And when I’m making binary to deploy , it is considering the exception.properties too. Did you know how to check all the files uploaded ?

Since I do not know anythiong about EC2, and nothing about your deployment process, I can’t tell you nothing reagrding this. I do assume that you simply upload your stuff using SCP or similar, and have full control over which data is transfered and to which place.

If not you have to change your mechanism of how your property file is discovered.

But another thing I just realise is, that in your first post you call the file Exception.properties while the code searches for exception.properties, EC2 is baked by linux and therefore case sensitive, please make sure the complete path exists AND the casing is correct! You dev machine is probably Mac or Windows, those filesystems are very forgiving casing stuff…

Oh sorry to say but the file name is “exception.properties” , mistakenly I’d put “Exception.properties”.

Then we can boil it down to the deployment/discovery of the file. You have to check your deployment process and make sure the file is at a place where your executable can find it and has set correct ownership and permissions.

Common sense is to put configuration in /etc/$APP_NAME

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.