automated-actions/AWS_EBS_VOLUME_LOST/SydneySummitDemo/aws_ebs_vol_lost_cfn.yaml [552:609]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import json
          import os
          import urllib.request
          from time import sleep

          es = str("http://" + os.environ['ESDOMAIN'])


          def lambda_handler(event, context):
              sleep(1)
              try:
                  pTime = event['PhdEventTime']
                  pId = event['PhdEventId']
              except:
                  pTime = 'ERROR_PARSING_JSON'
                  pId = 'ERROR_PARSING_JSON'

              iterateJson(event, pTime, pId)
              try:
                  ToEs(event, 'phd-full-events')
              except:
                  event['ESUpload'] = 'Failed'
              return event


          def iterateJson(jsn, time, id):
              pld = {}
              for i in jsn.items():
                  if type(i[1]) is str:
                      pld[i[0]] = i[1]
                  elif type(i[1]) is dict:
                      iterateJson(jsn[i[0]], time, id)
                  elif type(i[1]) is list:
                      for k in jsn[i[0]]:
                          iterateJson(k, time, id)

              pld['PhdEventTime'] = time
              pld['PhdEventId'] = id
              pld['ESUpload'] = 'Success'
              ToEs(pld, 'phd-events')


          def ToEs(doc, index):
              payload = json.dumps(doc).encode('utf8')
              rq = urllib.request.Request(es + '/' + index + '/doc', payload, {'Content-Type': 'application/json'}, method='POST')
              try:
                  f = urllib.request.urlopen(rq)
                  rsp = f.read()
                  f.close()
              except urllib.error.HTTPError:
                  rsp = 'Error uploading ' + str(doc)
              print(rsp)

  StepFunctionVolumeLost:
      Type: "AWS::StepFunctions::StateMachine"
      Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



automated-actions/AWS_EBS_VOLUME_LOST/stepbystep/step_3_stepfunctions_reinvent_workshop.yml [414:466]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import json
          import os
          import urllib.request
          from time import sleep
          es = str("http://" + os.environ['ESDOMAIN'])
          def lambda_handler(event, context):
              sleep(1)
              try:
                  pTime = event['PhdEventTime']
                  pId = event['PhdEventId']
              except:
                  pTime = 'ERROR_PARSING_JSON'
                  pId = 'ERROR_PARSING_JSON'
              iterateJson(event, pTime, pId)
              try:
                  ToEs(event, 'phd-full-events')
              except:
                  event['ESUpload'] = 'Failed'
              return event
          def iterateJson(jsn, time, id):
              pld = {}
              for i in jsn.items():
                  if type(i[1]) is str:
                      pld[i[0]] = i[1]
                  elif type(i[1]) is dict:
                      iterateJson(jsn[i[0]], time, id)
                  elif type(i[1]) is list:
                      for k in jsn[i[0]]:
                          iterateJson(k, time, id)
              pld['PhdEventTime'] = time
              pld['PhdEventId'] = id
              pld['ESUpload'] = 'Success'
              ToEs(pld, 'phd-events')
          def ToEs(doc, index):
              payload = json.dumps(doc).encode('utf8')
              rq = urllib.request.Request(es + '/' + index + '/doc', payload, {'Content-Type': 'application/json'}, method='POST')
              try:
                  f = urllib.request.urlopen(rq)
                  rsp = f.read()
                  f.close()
              except urllib.error.HTTPError:
                  rsp = 'Error uploading ' + str(doc)
              print(rsp)

####################
# Step Functions #
####################

  StepFunctionVolumeLost:
      Type: "AWS::StepFunctions::StateMachine"
      Properties:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



