1

Need help to fix the error and enable the instance to run issue free User Data script.

Issue: cloud-init is unable to execute awscli command. I have mentioned a custom script (which will be present on the instance created by my AMI) to run as part of User Data. The custom script is failing on the section where awscli command is mentioned.

Description: I am trying to achieve auto deployment of application content as soon as an instance is created from a certain AMI. For this I have placed the custom script on the instance and created AMI which will serve as template for future instances. The custom script has very simple logic of deployment and managing application service lifecycle (app||web||start||stop||status). The issue is coming when the script goes to execute aswcli command for fetching the war or static content from S3 bucket. It gives below error:

Snippet from cloud-init-output.log:

Mar 12 04:06:06 ip-XXX cloud-init: Deploying Static Content XXX.zip at location /var/www/html
Mar 12 04:06:06 ip-XXX cloud-init: /opt/deploy/deployment_V4.sh: line 94: aws: command not found
===================
Mar 12 04:06:06 ip-XXX cloud-init: Deploying WAR XXX.war at location /opt/tomcat/webapps
Mar 12 04:06:06 ip-XXX cloud-init: /opt/deploy/deployment_V4.sh: line 80: aws: command not found

Whereas, if I manually run the same custom deployment script from the instance, it deploys the content without error. Also if I run the "User Data" script manually on the instance, the deployment completes without any error.

Snippet:

[root@ip-XXX]# cd /var/lib/cloud/instance/scripts/
[root@ip-XXX scripts]# ./part-001
HTTPD Service is Stopped
TOMCAT Service is Stopped
VERSION is V4
Deploying Static Content XXX.zip at location /var/www/html
download: s3://<PATH>/XXX.zip to ../../../../../www/html/XXX.zip
Web Deployment Successful
VERSION is V4
Deploying WAR XXX.war at location /opt/tomcat/webapps
download: s3://<PATH>/XXX.war to ../../../../../../opt/tomcat/webapps/XXX.war
App Deployment Successful
HTTPD Service is Started
TOMCAT Service is Started

User Data:

#!/bin/sh
VERSION=V4
AD=/opt/deploy

#Run auto-deployment script
sh /opt/deploy/deployment_${VERSION}.sh stop
sh /opt/deploy/deployment_${VERSION}.sh web
sh /opt/deploy/deployment_${VERSION}.sh app
sh /opt/deploy/deployment_${VERSION}.sh start

NOTE:

1) OS is CentOS7_64Bit

2) Instance is enrolled to s3 enable role at the startup.

3) AWSCLI is installed on the instance and is part of AMI.

aws --version
aws-cli/1.11.56 Python/2.7.5 Linux/3.10.0-514.6.2.el7.x86_64 botocore/1.5.19
0

Where is the aws binary?

which aws

My guess is the directory where aws is is not in the path.

  • I have already added aws path to .bash_profile [root@ip-XXX ~]# which aws /root/.local/bin/aws [root@ip-XXX ~]# aws --version aws-cli/1.11.56 Python/2.7.5 Linux/3.10.0-514.6.2.el7.x86_64 botocore/1.5.19 – quark2sf Mar 12 '17 at 5:45
  • .bash_profile won't be used by userdata either because you're using sh or because it doesn't actually login as a user so it won't import user configuration – Robo Mar 12 '17 at 5:48
  • Then should i have to put the aws path in my custom script where the aws call is made? or any other way you would suggest? – quark2sf Mar 12 '17 at 5:52
  • I would just set the PATH in your user data script – Robo Mar 12 '17 at 5:53
  • Thank You Robo. I added the "export PATH=~/.local/bin:\$PATH" as part of "User Data" which did the trick. – quark2sf Mar 12 '17 at 6:16
1

Thanks to @Robo the issue is resolved.

As per his direction, I have added the "export PATH=~/.local/bin:\$PATH" as part of "User Data" which did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.