automated-actions/AWS_EBS_VOLUME_LOST/SydneySummitDemo/aws_ebs_vol_lost_cfn.yaml [376:417]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import boto3,json,datetime
          
          def datetime_handler(x):
              if isinstance(x, datetime.datetime):
                  return x.isoformat()
              raise TypeError("Unknown type")
          
          def lambda_handler(event, context):
              stackname = event['ResourceStack']['StackName']
              client = boto3.client('cloudformation')
              response = client.describe_stack_events(StackName=stackname)
              endsearch = False
              stackevents = []
              for i in response['StackEvents']:
                  HasResourceStatusReason = i.get('ResourceStatusReason')
                  if HasResourceStatusReason != None:
                      if i['ResourceStatusReason'] == "User Initiated":
                          stackevents.append(i)
                          break
                      else:
                          stackevents.append(i)
                  else:
                      stackevents.append(i)
              json_container = json.dumps(stackevents,default=datetime_handler)
              print(json_container)
              event['ResourceStack']['StackEvents'] = json.loads(json_container)
          
              
              stackresponse = client.describe_stack_resource(StackName=stackname, LogicalResourceId='EC2Instance')
              restoredinstance = stackresponse['StackResourceDetail']['PhysicalResourceId']
              event['RestoredResources']['ReplacementInstance'] = restoredinstance
              
              
              ec2client = boto3.client('ec2')
              volresponse = ec2client.describe_volumes(Filters=[{'Name': 'attachment.instance-id','Values': [restoredinstance]}])
              
              vol_json_container = json.dumps(volresponse['Volumes'],default=datetime_handler)
              event['RestoredResources']['RestoredVolumes'] = json.loads(vol_json_container)
              
              return event
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



automated-actions/AWS_EBS_VOLUME_LOST/stepbystep/step_3_stepfunctions_reinvent_workshop.yml [241:282]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import boto3,json,datetime
          
          def datetime_handler(x):
              if isinstance(x, datetime.datetime):
                  return x.isoformat()
              raise TypeError("Unknown type")
          
          def lambda_handler(event, context):
              stackname = event['ResourceStack']['StackName']
              client = boto3.client('cloudformation')
              response = client.describe_stack_events(StackName=stackname)
              endsearch = False
              stackevents = []
              for i in response['StackEvents']:
                  HasResourceStatusReason = i.get('ResourceStatusReason')
                  if HasResourceStatusReason != None:
                      if i['ResourceStatusReason'] == "User Initiated":
                          stackevents.append(i)
                          break
                      else:
                          stackevents.append(i)
                  else:
                      stackevents.append(i)
              json_container = json.dumps(stackevents,default=datetime_handler)
              print(json_container)
              event['ResourceStack']['StackEvents'] = json.loads(json_container)
          
              
              stackresponse = client.describe_stack_resource(StackName=stackname, LogicalResourceId='EC2Instance')
              restoredinstance = stackresponse['StackResourceDetail']['PhysicalResourceId']
              event['RestoredResources']['ReplacementInstance'] = restoredinstance
              
              
              ec2client = boto3.client('ec2')
              volresponse = ec2client.describe_volumes(Filters=[{'Name': 'attachment.instance-id','Values': [restoredinstance]}])
              
              vol_json_container = json.dumps(volresponse['Volumes'],default=datetime_handler)
              event['RestoredResources']['RestoredVolumes'] = json.loads(vol_json_container)
              
              return event
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



