I have an AutoScale group, that is launched when a CloudWatch alarm goes off, when there's a message in a SQS queue.
But I don't want to create another CloudWatch alarm that decreases the number of Instances in the AutoScale group because the task being made in that Instance might take longer than the Alarm settings.
So the way I tried to do was, once the Instance is created, the user-data that I passed as ".sh" file, runs the task I want, waits until it finishes, copies the file to S3 and terminates the instance.
Unfortunately, the file does get into S3 but it's empty and the instance never shuts down.
I've read this is possible to do with something like lifecycle-hooks but I wanted to know if it's possible to do the way explained above.
My user data is as follows:
#!/bin/bash
runuser -l ec2-user -c "cd /my-directory && nohup execute-my-task --trace > /logs-directory/my-log-file.log & "
PID=$!
wait $PID
runuser -l ec2-user -c "aws s3 cp /logs-directory/my-log-file.log s3://-my-logs-bucket/my-log-file.log"
PID2=$!
wait $PID2
runuser -l ec2-user -c "shutdown -h now"
Thanks.
Aucun commentaire:
Enregistrer un commentaire