CreateLayer unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRestW rest;
bool success;
CkAuthAwsW authAws;
authAws.put_AccessKey(L"AWS_ACCESS_KEY");
authAws.put_SecretKey(L"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.put_Region(L"us-west-2");
authAws.put_ServiceName(L"opsworks");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://opsworks.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect(L"opsworks.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
CkJsonObjectW json;
json.UpdateString(L"Attributes.string",L"string");
json.UpdateInt(L"AutoAssignElasticIps",123);
json.UpdateInt(L"AutoAssignPublicIps",123);
json.UpdateInt(L"CloudWatchLogsConfiguration.Enabled",123);
json.UpdateInt(L"CloudWatchLogsConfiguration.LogStreams[0].BatchCount",123);
json.UpdateInt(L"CloudWatchLogsConfiguration.LogStreams[0].BatchSize",123);
json.UpdateInt(L"CloudWatchLogsConfiguration.LogStreams[0].BufferDuration",123);
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].DatetimeFormat",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].Encoding",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].File",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].FileFingerprintLines",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].InitialPosition",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].LogGroupName",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].MultiLineStartPattern",L"string");
json.UpdateString(L"CloudWatchLogsConfiguration.LogStreams[0].TimeZone",L"string");
json.UpdateString(L"CustomInstanceProfileArn",L"string");
json.UpdateString(L"CustomJson",L"string");
json.UpdateString(L"CustomRecipes.Configure[0]",L"string");
json.UpdateString(L"CustomRecipes.Deploy[0]",L"string");
json.UpdateString(L"CustomRecipes.Setup[0]",L"string");
json.UpdateString(L"CustomRecipes.Shutdown[0]",L"string");
json.UpdateString(L"CustomRecipes.Undeploy[0]",L"string");
json.UpdateString(L"CustomSecurityGroupIds[0]",L"string");
json.UpdateInt(L"EnableAutoHealing",123);
json.UpdateInt(L"InstallUpdatesOnBoot",123);
json.UpdateInt(L"LifecycleEventConfiguration.Shutdown.DelayUntilElbConnectionsDrained",123);
json.UpdateInt(L"LifecycleEventConfiguration.Shutdown.ExecutionTimeout",123);
json.UpdateString(L"Name",L"string");
json.UpdateString(L"Packages[0]",L"string");
json.UpdateString(L"Shortname",L"string");
json.UpdateString(L"StackId",L"string");
json.UpdateString(L"Type",L"string");
json.UpdateInt(L"UseEbsOptimizedInstances",123);
json.UpdateInt(L"VolumeConfigurations[0].Encrypted",123);
json.UpdateInt(L"VolumeConfigurations[0].Iops",123);
json.UpdateString(L"VolumeConfigurations[0].MountPoint",L"string");
json.UpdateInt(L"VolumeConfigurations[0].NumberOfDisks",123);
json.UpdateInt(L"VolumeConfigurations[0].RaidLevel",123);
json.UpdateInt(L"VolumeConfigurations[0].Size",123);
json.UpdateString(L"VolumeConfigurations[0].VolumeType",L"string");
// The JSON request body created by the above code:
// {
// "Attributes": {
// "string": "string"
// },
// "AutoAssignElasticIps": boolean,
// "AutoAssignPublicIps": boolean,
// "CloudWatchLogsConfiguration": {
// "Enabled": boolean,
// "LogStreams": [
// {
// "BatchCount": number,
// "BatchSize": number,
// "BufferDuration": number,
// "DatetimeFormat": "string",
// "Encoding": "string",
// "File": "string",
// "FileFingerprintLines": "string",
// "InitialPosition": "string",
// "LogGroupName": "string",
// "MultiLineStartPattern": "string",
// "TimeZone": "string"
// }
// ]
// },
// "CustomInstanceProfileArn": "string",
// "CustomJson": "string",
// "CustomRecipes": {
// "Configure": [
// "string"
// ],
// "Deploy": [
// "string"
// ],
// "Setup": [
// "string"
// ],
// "Shutdown": [
// "string"
// ],
// "Undeploy": [
// "string"
// ]
// },
// "CustomSecurityGroupIds": [
// "string"
// ],
// "EnableAutoHealing": boolean,
// "InstallUpdatesOnBoot": boolean,
// "LifecycleEventConfiguration": {
// "Shutdown": {
// "DelayUntilElbConnectionsDrained": boolean,
// "ExecutionTimeout": number
// }
// },
// "Name": "string",
// "Packages": [
// "string"
// ],
// "Shortname": "string",
// "StackId": "string",
// "Type": "string",
// "UseEbsOptimizedInstances": boolean,
// "VolumeConfigurations": [
// {
// "Encrypted": boolean,
// "Iops": number,
// "MountPoint": "string",
// "NumberOfDisks": number,
// "RaidLevel": number,
// "Size": number,
// "VolumeType": "string"
// }
// ]
// }
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"OpsWorks_20130218.CreateLayer");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jResp;
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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *LayerId = jResp.stringOf(L"LayerId");
// A sample JSON response body parsed by the above code:
// {
// "LayerId": "string"
// }
}