Chilkat Online Tools

GetJob DataFlex Example

Amazon Braket

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vAuthAws
    Handle hoAuthAws
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
    Handle hoJResp
    String sEventType
    String sMessage
    Integer iTimeOfEvent
    String sChannelName
    String sContentType
    String sS3DataSourceS3Uri
    String sUri
    String sCompressionType
    String sEntryPoint
    String sS3Uri
    Integer iBillableDuration
    String sLocalPath
    String sCheckpointConfigS3Uri
    Integer iCreatedAt
    String sDevice
    Integer iEndedAt
    String sFailureReason
    String sV_String
    Integer iInstanceCount
    String sInstanceType
    Integer iVolumeSizeInGb
    String sJobArn
    String sJobName
    String sKmsKeyId
    String sS3Path
    String sRoleArn
    Integer iStartedAt
    String sStatus
    Integer iMaxRuntimeInSeconds
    String sTagsString
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
    If (Not(IsComObjectCreated(hoAuthAws))) Begin
        Send CreateComObject of hoAuthAws
    End
    Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
    Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY"

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    Set ComRegion Of hoAuthAws To "us-west-2"
    Set ComServiceName Of hoAuthAws To "braket"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    // URL: https://braket.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    Get ComConnect Of hoRest "braket.us-west-2.amazonaws.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
    Get ComAddHeader Of hoRest "X-Amz-Target" "GetJob" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "GET" "/job/{jobArn}" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    Showln "response status code = " iRespStatusCode
    If (iRespStatusCode <> 200) Begin
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    Get ComStringOf Of hoJResp "algorithmSpecification.containerImage.uri" To sUri
    Get ComStringOf Of hoJResp "algorithmSpecification.scriptModeConfig.compressionType" To sCompressionType
    Get ComStringOf Of hoJResp "algorithmSpecification.scriptModeConfig.entryPoint" To sEntryPoint
    Get ComStringOf Of hoJResp "algorithmSpecification.scriptModeConfig.s3Uri" To sS3Uri
    Get ComIntOf Of hoJResp "billableDuration" To iBillableDuration
    Get ComStringOf Of hoJResp "checkpointConfig.localPath" To sLocalPath
    Get ComStringOf Of hoJResp "checkpointConfig.s3Uri" To sCheckpointConfigS3Uri
    Get ComIntOf Of hoJResp "createdAt" To iCreatedAt
    Get ComStringOf Of hoJResp "deviceConfig.device" To sDevice
    Get ComIntOf Of hoJResp "endedAt" To iEndedAt
    Get ComStringOf Of hoJResp "failureReason" To sFailureReason
    Get ComStringOf Of hoJResp "hyperParameters.string" To sV_String
    Get ComIntOf Of hoJResp "instanceConfig.instanceCount" To iInstanceCount
    Get ComStringOf Of hoJResp "instanceConfig.instanceType" To sInstanceType
    Get ComIntOf Of hoJResp "instanceConfig.volumeSizeInGb" To iVolumeSizeInGb
    Get ComStringOf Of hoJResp "jobArn" To sJobArn
    Get ComStringOf Of hoJResp "jobName" To sJobName
    Get ComStringOf Of hoJResp "outputDataConfig.kmsKeyId" To sKmsKeyId
    Get ComStringOf Of hoJResp "outputDataConfig.s3Path" To sS3Path
    Get ComStringOf Of hoJResp "roleArn" To sRoleArn
    Get ComIntOf Of hoJResp "startedAt" To iStartedAt
    Get ComStringOf Of hoJResp "status" To sStatus
    Get ComIntOf Of hoJResp "stoppingCondition.maxRuntimeInSeconds" To iMaxRuntimeInSeconds
    Get ComStringOf Of hoJResp "tags.string" To sTagsString
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "events" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "events[i].eventType" To sEventType
        Get ComStringOf Of hoJResp "events[i].message" To sMessage
        Get ComIntOf Of hoJResp "events[i].timeOfEvent" To iTimeOfEvent
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "inputDataConfig" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "inputDataConfig[i].channelName" To sChannelName
        Get ComStringOf Of hoJResp "inputDataConfig[i].contentType" To sContentType
        Get ComStringOf Of hoJResp "inputDataConfig[i].dataSource.s3DataSource.s3Uri" To sS3DataSourceS3Uri
        Move (i + 1) To i
    Loop

    // A sample JSON response body parsed by the above code:

    // {
    //   "algorithmSpecification": {
    //     "containerImage": {
    //       "uri": "string"
    //     },
    //     "scriptModeConfig": {
    //       "compressionType": "string",
    //       "entryPoint": "string",
    //       "s3Uri": "string"
    //     }
    //   },
    //   "billableDuration": number,
    //   "checkpointConfig": {
    //     "localPath": "string",
    //     "s3Uri": "string"
    //   },
    //   "createdAt": number,
    //   "deviceConfig": {
    //     "device": "string"
    //   },
    //   "endedAt": number,
    //   "events": [
    //     {
    //       "eventType": "string",
    //       "message": "string",
    //       "timeOfEvent": number
    //     }
    //   ],
    //   "failureReason": "string",
    //   "hyperParameters": {
    //     "string": "string"
    //   },
    //   "inputDataConfig": [
    //     {
    //       "channelName": "string",
    //       "contentType": "string",
    //       "dataSource": {
    //         "s3DataSource": {
    //           "s3Uri": "string"
    //         }
    //       }
    //     }
    //   ],
    //   "instanceConfig": {
    //     "instanceCount": number,
    //     "instanceType": "string",
    //     "volumeSizeInGb": number
    //   },
    //   "jobArn": "string",
    //   "jobName": "string",
    //   "outputDataConfig": {
    //     "kmsKeyId": "string",
    //     "s3Path": "string"
    //   },
    //   "roleArn": "string",
    //   "startedAt": number,
    //   "status": "string",
    //   "stoppingCondition": {
    //     "maxRuntimeInSeconds": number
    //   },
    //   "tags": {
    //     "string": "string"
    //   }
    // }


End_Procedure