Last active
March 7, 2023 08:39
-
-
Save cipulan/f20a5f3c26315a5e92226e0ac092de0c to your computer and use it in GitHub Desktop.
Cron AWS Auto Scaling Group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Collect some information about this instance | |
MY_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
MY_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//') | |
MY_ASG=$(aws autoscaling describe-auto-scaling-instances --region $MY_REGION --instance-ids $MY_ID --query "AutoScalingInstances[].AutoScalingGroupName" --output text) | |
# Query the ASG | |
FIRST_ID=$(aws autoscaling describe-auto-scaling-groups --region $MY_REGION --auto-scaling-group-name $MY_ASG --query "AutoScalingGroups[].Instances[0].InstanceId" --output text) | |
if [ "$FIRST_ID" == "$MY_ID" ]; then | |
exit 0 | |
else | |
exit 1 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "VisualEditor0", | |
"Effect": "Allow", | |
"Action": [ | |
"autoscaling:DescribeAutoScalingInstances", | |
"ec2:DescribeInstances", | |
"autoscaling:DescribeAutoScalingGroups", | |
"ec2:DescribeInstanceAttribute", | |
"ec2:DescribeInstanceStatus" | |
], | |
"Resource": "*" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/10 * * * * /bin/bash /opt/asg-cron.sh && /bin/bash /pat/to//file/mautic_campaign_trigger.sh >/dev/null 2>&1 | |
*/5 * * * * /bin/bash /opt/asg-cron.sh && /bin/bash /pat/to//file/mautic_emails_send.sh >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment