DataFlex
DataFlex
AWS KMS List Keys
See more AWS KMS Examples
Gets a list of all KMS keys in the caller's AWS account and Region.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vAuthAws
Handle hoAuthAws
String sStrJson
Handle hoJson
String sKeyArn
String sKeyId
Integer iKeyCount
Boolean iTruncated
Integer i
Integer iCount_i
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// 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
// Connect to the Amazon AWS REST server.
// Make sure to use the region that is correct for you.
// such as https://kms.us-west-2.amazonaws.com/
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "kms.us-west-2.amazonaws.com" iPort iBTls iBAutoReconnect To iSuccess
// Provide AWS credentials for the REST call.
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"
// the region should match our URL above..
Set ComRegion Of hoAuthAws To "us-west-2"
Set ComServiceName Of hoAuthAws To "kms"
Get pvComObject of hoAuthAws to vAuthAws
Get ComSetAuthAws Of hoRest vAuthAws To iSuccess
Get ComAddHeader Of hoRest "X-Amz-Target" "TrentService.ListKeys" To iSuccess
Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
Get ComFullRequestString Of hoRest "POST" "/" "{}" To sStrJson
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// A successful response will have a status code equal to 200.
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "response status code = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "response status text = " sTemp1
Get ComResponseHeader Of hoRest To sTemp1
Showln "response header: " sTemp1
Showln "response body: " sStrJson
Procedure_Return
End
// Examine the successful JSON response (shown below)
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComLoad Of hoJson sStrJson To iSuccess
Set ComEmitCompact Of hoJson To False
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// Sample output:
// {
// "KeyCount": 4,
// "Keys": [
// {
// "KeyArn": "arn:aws:kms:us-west-2:954491834127:key/082f8520-7afc-4a09-b703-89b7243072e5",
// "KeyId": "082f8520-7afc-4a09-b703-89b7243072e5"
// },
// {
// "KeyArn": "arn:aws:kms:us-west-2:954491834127:key/17432483-ff08-4950-93d3-f46ebb5e17d1",
// "KeyId": "17432483-ff08-4950-93d3-f46ebb5e17d1"
// },
// {
// "KeyArn": "arn:aws:kms:us-west-2:954491834127:key/1b0e5b3c-0675-4510-adb6-a75b40a93da0",
// "KeyId": "1b0e5b3c-0675-4510-adb6-a75b40a93da0"
// },
// {
// "KeyArn": "arn:aws:kms:us-west-2:954491834127:key/265e3993-428b-4581-9466-b1030a53062f",
// "KeyId": "265e3993-428b-4581-9466-b1030a53062f"
// },
// ],
// "Truncated": false
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
Get ComIntOf Of hoJson "KeyCount" To iKeyCount
Get ComBoolOf Of hoJson "Truncated" To iTruncated
Move 0 To i
Get ComSizeOfArray Of hoJson "Keys" To iCount_i
While (i < iCount_i)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "Keys[i].KeyArn" To sKeyArn
Get ComStringOf Of hoJson "Keys[i].KeyId" To sKeyId
Move (i + 1) To i
Loop
End_Procedure