简体   繁体   中英

python script in user data not running when ec2 instance boots up

I am trying to do some object detection by running a custom detection script on aws ec2. I have added the user data script as follows for the instance

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, always]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/sh
cd /home/ubuntu/path/to/script
sudo python3 strawberry_count_new.py

However, when my lambda function copies the image to the instance, the script doess not perform detection. Im not getting any output. When I check my running processes, the python script is running. Im not sure why its not processing the input image coming from the s3. When I run the same script inside the instance, it processes the same input image.

To check the output of your script, and in this case, it's a good practice that you put the sufficient logging in the script, you can redirect the user-data output to a specific path and later go check this output file, this would be done including the following line as your script's first line:

exec > >(tee /var/log/user-data-aux.log|logger -t user-data -s 2>/dev/console) 2>&1

Later you can verify what's happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM