Chilkat Online Tools

GetJob Node.js Example

Amazon Braket

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node17-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node17-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node17-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node17-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node17-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node17-macosx');
}

function chilkatExample() {

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

    var rest = new chilkat.Rest();
    var success;

    var authAws = new chilkat.AuthAws();
    authAws.AccessKey = "AWS_ACCESS_KEY";
    authAws.SecretKey = "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.)
    authAws.Region = "us-west-2";
    authAws.ServiceName = "braket";
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://braket.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("braket.us-west-2.amazonaws.com",443,true,true);
    if (success !== true) {
        console.log("ConnectFailReason: " + rest.ConnectFailReason);
        console.log(rest.LastErrorText);
        return;
    }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","GetJob");

    var sbResponseBody = new chilkat.StringBuilder();
    success = rest.FullRequestNoBodySb("GET","/job/{jobArn}",sbResponseBody);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    var respStatusCode = rest.ResponseStatusCode;
    console.log("response status code = " + respStatusCode);
    if (respStatusCode !== 200) {
        console.log("Response Header:");
        console.log(rest.ResponseHeader);
        console.log("Response Body:");
        console.log(sbResponseBody.GetAsString());
        return;
    }

    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);

    // 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

    var eventType;
    var message;
    var timeOfEvent;
    var channelName;
    var contentType;
    var S3DataSourceS3Uri;

    var Uri = jResp.StringOf("algorithmSpecification.containerImage.uri");
    var CompressionType = jResp.StringOf("algorithmSpecification.scriptModeConfig.compressionType");
    var EntryPoint = jResp.StringOf("algorithmSpecification.scriptModeConfig.entryPoint");
    var S3Uri = jResp.StringOf("algorithmSpecification.scriptModeConfig.s3Uri");
    var billableDuration = jResp.IntOf("billableDuration");
    var LocalPath = jResp.StringOf("checkpointConfig.localPath");
    var checkpointConfigS3Uri = jResp.StringOf("checkpointConfig.s3Uri");
    var createdAt = jResp.IntOf("createdAt");
    var Device = jResp.StringOf("deviceConfig.device");
    var endedAt = jResp.IntOf("endedAt");
    var failureReason = jResp.StringOf("failureReason");
    var v_String = jResp.StringOf("hyperParameters.string");
    var InstanceCount = jResp.IntOf("instanceConfig.instanceCount");
    var InstanceType = jResp.StringOf("instanceConfig.instanceType");
    var VolumeSizeInGb = jResp.IntOf("instanceConfig.volumeSizeInGb");
    var jobArn = jResp.StringOf("jobArn");
    var jobName = jResp.StringOf("jobName");
    var KmsKeyId = jResp.StringOf("outputDataConfig.kmsKeyId");
    var S3Path = jResp.StringOf("outputDataConfig.s3Path");
    var roleArn = jResp.StringOf("roleArn");
    var startedAt = jResp.IntOf("startedAt");
    var status = jResp.StringOf("status");
    var MaxRuntimeInSeconds = jResp.IntOf("stoppingCondition.maxRuntimeInSeconds");
    var tagsString = jResp.StringOf("tags.string");
    var i = 0;
    var count_i = jResp.SizeOfArray("events");
    while (i < count_i) {
        jResp.I = i;
        eventType = jResp.StringOf("events[i].eventType");
        message = jResp.StringOf("events[i].message");
        timeOfEvent = jResp.IntOf("events[i].timeOfEvent");
        i = i+1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("inputDataConfig");
    while (i < count_i) {
        jResp.I = i;
        channelName = jResp.StringOf("inputDataConfig[i].channelName");
        contentType = jResp.StringOf("inputDataConfig[i].contentType");
        S3DataSourceS3Uri = jResp.StringOf("inputDataConfig[i].dataSource.s3DataSource.s3Uri");
        i = i+1;
    }

    // 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"
    //   }
    // }

}

chilkatExample();