Why Event "BeforeHostTerminate" would detach volume before terminating 
instance?
This's the reason why my boto3 script couldn't make a volume get deleted 
after the termination of instance on your Scalr GUI, but work fine on aws 
console termination of instance.
------
response = client.modify_instance_attribute(
  InstanceId = 'i-d14b9644',
  BlockDeviceMappings = [
    {
       'DeviceName': '/dev/sdg',
       'Ebs': {
          'DeleteOnTermination': True
       },
    },
  ],
)
------
Can I modify the default behavior of Event "BeforeHostTerminate"? Thanks!


Brant

On Sunday, August 14, 2016 at 4:13:24 PM UTC+8, Brant Fortest wrote:
>
>
> Hi, Team,
> I'm trying to make a web-hook to make a storage get deleted after its 
> instance got terminated.
> Following your guide. "Using Amazon Route 53 DNS with Scalr" 
> https://scalr-wiki.atlassian.net/wiki/display/docs/Using+Amazon+Route+53+DNS+with+Scalr
>
> Here's my script 
>
> ------------------------
>
> root@ec2:~/script# cat /root/script/scalr-ec2.py
>
> #!/usr/bin/env python
>
> # -*- coding: utf-8 -*-
>
>  
>
> import json
>
> import hmac
>
> import pytz
>
> import boto3
>
> import logging
>
> import binascii
>
> import dateutil.parser
>
> from hashlib import sha1
>
> from datetime import datetime
>
> from flask import Flask, request
>
>  
>
> app = Flask(__name__)
>
>  
>
>  
>
> SCALR_SIGNING_KEY = 
> 'H3fhHPYOKswyMAz6/ztP+0wLrjfpXiBZ8+7Ms23V0G7pKxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
>
>  
>
> @app.route("/", methods=['POST'])
>
> def webhook_listener():
>
>     if not validateRequest(request):
>
>         return 'Invalid signature'
>
>  
>
>     data = json.loads(request.data)
>
>     if not 'eventName' in data or not 'data' in data:
>
>         return 'Invalid call'
>
>  
>
>     if data['eventName'] == 'BeforeHostTerminate':
>
>         deleteOnTermination(data['data'])
>
>     return "Ok"
>
>  
>
> def deleteOnTermination(data):
>
>     client = boto3.client('ec2')
>
>     iid =  data['SCALR_INSTANCE_ID']
>
>     logging.debug('Set DeleteOnTermination Flag on %s', iid)
>
>     response = client.modify_instance_attribute(
>
>         InstanceId = 'iid',
>
>         BlockDeviceMappings=[
>
>           {
>
>             'DeviceName': '/dev/sdg',
>
>             'Ebs': {
>
>                 'DeleteOnTermination': True
>
>             },
>
>           },
>
>         ],
>
>       )
>
>     logging.info(response)
>
>  
>
> def validateRequest(request):
>
>     if not 'X-Signature' in request.headers or not 'Date' in 
> request.headers:
>
>         return False
>
>     date = request.headers['Date']
>
>     body = request.data
>
>     expected_signature = binascii.hexlify(hmac.new(SCALR_SIGNING_KEY, body 
> + date, sha1).digest())
>
>     if expected_signature != request.headers['X-Signature']:
>
>         return False
>
>     date = dateutil.parser.parse(date)
>
>     now = datetime.now(pytz.utc)
>
>     delta = abs((now - date).total_seconds())
>
>     return delta < 300 # Requests are validfor 5 minutes
>
>     
>
>  
>
> if __name__ == "__main__":
>
>     app.run(host='0.0.0.0')
>
>  
>
> ------------------------
>
>
> According to Webhook Notifications 
> <https://scalr-wiki.atlassian.net/wiki/display/docs/Webhook+Notifications>, 
> these  four should contain same Instance ID. 
>
> "SCALR_CLOUD_SERVER_ID", "SCALR_INSTANCE_ID", 
> "SCALR_EVENT_CLOUD_SERVER_ID", "SCALR_EVENT_INSTANCE_ID"
>
> But still I got this error. 
>
>
> Am I missing something here? Thanks!
>
>
> <https://lh3.googleusercontent.com/-amfhO2fvEXI/V7AnXcItQRI/AAAAAAAAAHQ/UNoxHFlcvZ0SNJj_6nbObcC3cq_ZmKqEwCLcB/s1600/Value%2Bfor%2Bparameter%2BinstancedId%2Bis%2Binvalid.PNG>
>
>
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"scalr-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to