Cloud-init is failing to execute awscli command in User Data

amazon ec2amazon s3aws-clicentos7cloud-init

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

Best Answer

Where is the aws binary?

which aws

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