AndrewFarley/AWS-Automated-Daily-Instance-AMI-Snapshots

Not creating image for all instances

charterresources opened this issue · 7 comments

Thank you for your contribution @AndrewFarley
Everything works perfect without error but for some unknown reason it only creates images for 7 out of 19 instances.
All the instances have the tag "Backup" and retention tag with a value of "11"
When I run a test, it creates images of the same 7 instances over and over again. If I remove the tag "Backup" from these 7 instances, the test run will create 1 out of remaining 12 instances with the tag "Backup". If I remove the tag from this instance too, the test will create another one of the remaining 11 instances.
Please help.

Here is the Log output:

START RequestId: 7b1b6c6f-7307-11e8-a0a3-a5e096e1e21f Version: $LATEST
Scanning region: us-east-1
Scanning for instances with tags (backup,Backup)
Found 7 instances to backup...
Instance: i-#############
Name: @@@@@@
Time: 11 days
AMI: ami-#####
Instance: i-#############
Name: @@@@@@@
Time: 11 days
AMI: ami-#####
Instance: i-#############
Name: @@@@@
Time: 11 days
AMI: ami-#####
Instance: i-#######
Name: @@@@@
Time: 11 days
AMI: ami-######
Instance: i-#############
Name: @@@@@
Time: 11 days
AMI: ami-######
Instance: i-###########
Name: @@@
Time: 11 days
AMI: ami-#######
Instance: i-############
Name: @@@
Time: 11 days
AMI: ami-########
Scanning for AMIs with tags (CESRBackupInstanceRotater)
END RequestId: 7b1b6c6f-7307-11e8-a0a3-a5e096e1e21f
REPORT RequestId: 7b1b6c6f-7307-11e8-a0a3-a5e096e1e21f Duration: 3154.76 ms Billed Duration: 3200 ms Memory Size: 128 MB Max Memory Used: 46 MB

@charterresources I'm sorry to hear that, I'd love to help you solve it. Could you please run the following command for me...

AWS_DEFAULT_REGION=us-east-1 aws ec2 describe-instances --filters Name=tag-key,Values=backup,Backup | grep InstanceId

This is the command-line equivalent of the command it is running above. Tell me if it shows a list of 7, or all your 19 images in that list. If it shows a list of full 19, could you remove the grep off the end, and mail me your output so I can fix it? farley at neonsurge dot com. If it only shows 7, then it must be something you're doing with the wrong tag key. Let me know!

Cheers!

Thank you @AndrewFarley for your response.
The command shows all 19 instances with and without grep.
Looking at the detailed list, I see that 13 instances have the exact same reservation IDs (they were all launched together).
So your lambda function takes images of all 6 instances with different reservation IDs plus 1 out of the 13 instances that have exact same reservation IDs.
hope that makes sense.

@charterresources That makes sense... I think I know how to fix it... give me a few hours and I'll try to kick out a fix for you. Cheers!

@charterresources Confirmed your problem and made a fix against a test environment, enjoy!

@charterresources Additionally, I saw you limited to a single region, I can make this a variable in Serverless... so you don't have to modify code. Any other requests? Cheers!

@AndrewFarley thank you Andrew. Works like a charm.
Found 19 instances to backup...
Variable for region would definitely be a plus for the function but not a priority I think.
One suggestion I would humbly have is to tag the snapshots using the tags of corresponding volumes.
thanks
~Samet

Ooh @charterresources I'm tagging the snapshots with the tags from the instance, not what the volume had. Great point... :) I'll add two issues to adjust this you can follow them, I'll get around to them soon. Cheers!