GetImageRecipe delphiDll Example
var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
deviceName: PWideChar;
DeleteOnTermination: Integer;
Encrypted: Integer;
Iops: Integer;
KmsKeyId: PWideChar;
SnapshotId: PWideChar;
Throughput: Integer;
VolumeSize: Integer;
VolumeType: PWideChar;
noDevice: PWideChar;
virtualName: PWideChar;
componentArn: PWideChar;
j: Integer;
count_j: Integer;
name: PWideChar;
k: Integer;
count_k: Integer;
strVal: PWideChar;
UninstallAfterBuild: Integer;
UserDataOverride: PWideChar;
Arn: PWideChar;
DateCreated: PWideChar;
Description: PWideChar;
Name: PWideChar;
Owner: PWideChar;
ParentImage: PWideChar;
Platform: PWideChar;
v_String: PWideChar;
v_Type: PWideChar;
Version: PWideChar;
WorkingDirectory: PWideChar;
requestId: PWideChar;
i: Integer;
count_i: Integer;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(authAws,'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.)
CkAuthAws_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(authAws,'imagebuilder');
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://imagebuilder.us-west-2.amazonaws.com/
// Use the same region as specified above.
success := CkRest_Connect(rest,'imagebuilder.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','GetImageRecipe');
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/GetImageRecipe',sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkRest__responseHeader(rest));
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
Exit;
end;
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,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
UninstallAfterBuild := CkJsonObject_IntOf(jResp,'imageRecipe.additionalInstanceConfiguration.systemsManagerAgent.uninstallAfterBuild');
UserDataOverride := CkJsonObject__stringOf(jResp,'imageRecipe.additionalInstanceConfiguration.userDataOverride');
Arn := CkJsonObject__stringOf(jResp,'imageRecipe.arn');
DateCreated := CkJsonObject__stringOf(jResp,'imageRecipe.dateCreated');
Description := CkJsonObject__stringOf(jResp,'imageRecipe.description');
Name := CkJsonObject__stringOf(jResp,'imageRecipe.name');
Owner := CkJsonObject__stringOf(jResp,'imageRecipe.owner');
ParentImage := CkJsonObject__stringOf(jResp,'imageRecipe.parentImage');
Platform := CkJsonObject__stringOf(jResp,'imageRecipe.platform');
v_String := CkJsonObject__stringOf(jResp,'imageRecipe.tags.string');
v_Type := CkJsonObject__stringOf(jResp,'imageRecipe.type');
Version := CkJsonObject__stringOf(jResp,'imageRecipe.version');
WorkingDirectory := CkJsonObject__stringOf(jResp,'imageRecipe.workingDirectory');
requestId := CkJsonObject__stringOf(jResp,'requestId');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'imageRecipe.blockDeviceMappings');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
deviceName := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].deviceName');
DeleteOnTermination := CkJsonObject_IntOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.deleteOnTermination');
Encrypted := CkJsonObject_IntOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.encrypted');
Iops := CkJsonObject_IntOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.iops');
KmsKeyId := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.kmsKeyId');
SnapshotId := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.snapshotId');
Throughput := CkJsonObject_IntOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.throughput');
VolumeSize := CkJsonObject_IntOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.volumeSize');
VolumeType := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].ebs.volumeType');
noDevice := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].noDevice');
virtualName := CkJsonObject__stringOf(jResp,'imageRecipe.blockDeviceMappings[i].virtualName');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'imageRecipe.components');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
componentArn := CkJsonObject__stringOf(jResp,'imageRecipe.components[i].componentArn');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'imageRecipe.components[i].parameters');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
name := CkJsonObject__stringOf(jResp,'imageRecipe.components[i].parameters[j].name');
k := 0;
count_k := CkJsonObject_SizeOfArray(jResp,'imageRecipe.components[i].parameters[j].value');
while k < count_k do
begin
CkJsonObject_putK(jResp,k);
strVal := CkJsonObject__stringOf(jResp,'imageRecipe.components[i].parameters[j].value[k]');
k := k + 1;
end;
j := j + 1;
end;
i := i + 1;
end;
// A sample JSON response body parsed by the above code:
// {
// "imageRecipe": {
// "additionalInstanceConfiguration": {
// "systemsManagerAgent": {
// "uninstallAfterBuild": boolean
// },
// "userDataOverride": "string"
// },
// "arn": "string",
// "blockDeviceMappings": [
// {
// "deviceName": "string",
// "ebs": {
// "deleteOnTermination": boolean,
// "encrypted": boolean,
// "iops": number,
// "kmsKeyId": "string",
// "snapshotId": "string",
// "throughput": number,
// "volumeSize": number,
// "volumeType": "string"
// },
// "noDevice": "string",
// "virtualName": "string"
// }
// ],
// "components": [
// {
// "componentArn": "string",
// "parameters": [
// {
// "name": "string",
// "value": [
// "string"
// ]
// }
// ]
// }
// ],
// "dateCreated": "string",
// "description": "string",
// "name": "string",
// "owner": "string",
// "parentImage": "string",
// "platform": "string",
// "tags": {
// "string": "string"
// },
// "type": "string",
// "version": "string",
// "workingDirectory": "string"
// },
// "requestId": "string"
// }
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);