0

Hello I'm trying to create a CodeDeploy deployment for my golang application. I have an autoscaling group that uses a AMI I created that has all the libs I need installed. When I try to run CodeDeploy it exists with an error in my after_install:

LifecycleEvent - AfterInstall
Script - scripts/after_install.sh
[stderr]/opt/codedeploy-agent/deployment-root/a65d9a2e-fddd-471c-8ea1-c018792d00bd/d-4IKP3PP4Y/deployment-archive/scripts/after_install.sh: 
line 4: go: command not found

I know go is installed on the server I can verify by sshing into the server and running the go command. Initially I had my after_install hook run as root so that's why I thought it complained about go not being installed.

I updated it to run as ubuntu here is the appspec file

version: 0.0
os: linux
files:
  - source: ./
    destination: ./home/ubuntu/code
hooks:
  AfterInstall:
    - location: scripts/after_install.sh
      timeout: 180
      runas: ubuntu
  ApplicationStart:
    - location: scripts/application_start.sh
      timeout: 180
      runas: root

But I still get the error of go command not found. I SSH into the server as ubuntu user and I can clearly see go is installed.

I took it one step further and ran the after_install.sh file and it worked with no errors. What am I doing wrong here?

Just for the extra curious here is my after_install.sh file

#!/bin/bash

cd /home/ubuntu/code/vibeify/cmd/vibeify
go build
1
  • Where is go installed? Is that path configured for the ubuntu user? Add 'echo $PATH' to the script and confirm. Commented Apr 26, 2019 at 6:41

1 Answer 1

1

If you can use go command without the full installation path only in the interactive shell, check $HOME/.bashrc.

It may depends on OS default settings, but some OS default bashrc file includes scripts that does not load profile in non-interactive shell.

# open $HOME/.bashrc file
# and comment out these lines
case $- in
    *i*) ;;
      *) return;;
esac
Sign up to request clarification or add additional context in comments.

1 Comment

Environment variables like PATH should be in a profile file, not an rc file. There’s a reason they’re not loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.