Chilkat Online Tools

UpdateLayer Foxpro Example

AWS OpsWorks

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode

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

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.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.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "opsworks"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://opsworks.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("opsworks.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

* 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

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("Attributes.string","string")
loJson.UpdateInt("AutoAssignElasticIps",123)
loJson.UpdateInt("AutoAssignPublicIps",123)
loJson.UpdateInt("CloudWatchLogsConfiguration.Enabled",123)
loJson.UpdateInt("CloudWatchLogsConfiguration.LogStreams[0].BatchCount",123)
loJson.UpdateInt("CloudWatchLogsConfiguration.LogStreams[0].BatchSize",123)
loJson.UpdateInt("CloudWatchLogsConfiguration.LogStreams[0].BufferDuration",123)
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].DatetimeFormat","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].Encoding","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].File","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].FileFingerprintLines","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].InitialPosition","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].LogGroupName","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].MultiLineStartPattern","string")
loJson.UpdateString("CloudWatchLogsConfiguration.LogStreams[0].TimeZone","string")
loJson.UpdateString("CustomInstanceProfileArn","string")
loJson.UpdateString("CustomJson","string")
loJson.UpdateString("CustomRecipes.Configure[0]","string")
loJson.UpdateString("CustomRecipes.Deploy[0]","string")
loJson.UpdateString("CustomRecipes.Setup[0]","string")
loJson.UpdateString("CustomRecipes.Shutdown[0]","string")
loJson.UpdateString("CustomRecipes.Undeploy[0]","string")
loJson.UpdateString("CustomSecurityGroupIds[0]","string")
loJson.UpdateInt("EnableAutoHealing",123)
loJson.UpdateInt("InstallUpdatesOnBoot",123)
loJson.UpdateString("LayerId","string")
loJson.UpdateInt("LifecycleEventConfiguration.Shutdown.DelayUntilElbConnectionsDrained",123)
loJson.UpdateInt("LifecycleEventConfiguration.Shutdown.ExecutionTimeout",123)
loJson.UpdateString("Name","string")
loJson.UpdateString("Packages[0]","string")
loJson.UpdateString("Shortname","string")
loJson.UpdateInt("UseEbsOptimizedInstances",123)
loJson.UpdateInt("VolumeConfigurations[0].Encrypted",123)
loJson.UpdateInt("VolumeConfigurations[0].Iops",123)
loJson.UpdateString("VolumeConfigurations[0].MountPoint","string")
loJson.UpdateInt("VolumeConfigurations[0].NumberOfDisks",123)
loJson.UpdateInt("VolumeConfigurations[0].RaidLevel",123)
loJson.UpdateInt("VolumeConfigurations[0].Size",123)
loJson.UpdateString("VolumeConfigurations[0].VolumeType","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,
*   "LayerId": "string",
*   "LifecycleEventConfiguration": {
*     "Shutdown": {
*       "DelayUntilElbConnectionsDrained": boolean,
*       "ExecutionTimeout": number
*     }
*   },
*   "Name": "string",
*   "Packages": [
*     "string"
*   ],
*   "Shortname": "string",
*   "UseEbsOptimizedInstances": boolean,
*   "VolumeConfigurations": [
*     {
*       "Encrypted": boolean,
*       "Iops": number,
*       "MountPoint": "string",
*       "NumberOfDisks": number,
*       "RaidLevel": number,
*       "Size": number,
*       "VolumeType": "string"
*     }
*   ]
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","OpsWorks_20130218.UpdateLayer")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

* If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody