Amazon DynamoDB: Describe Table Status, Keys, and Indexes
See more Amazon DynamoDB Examples
Display status, ARN, optional billing mode, key schema, and local/global secondary indexes. ItemCount and TableSizeBytes are approximate statistics updated about every six hours, not an exact count or readiness signal. Large values are printed as strings; on-demand tables need not have provisioned-capacity details.
This makes one status check. After CreateTable, retry an early ResourceNotFoundException with a bounded delay until ACTIVE. After deletion, ResourceNotFoundException means the table is gone if account, region, and name are correct.
Uses DynamoDB's regional JSON API: POST to /, application/x-amz-json-1.0, and an operation-specific X-Amz-Target: DynamoDB_20120810... header. The 20120810 API identifier is still current. Chilkat.Rest and AuthAws sign each request with AWS Signature Version 4, service dynamodb. Set the region once; the example builds the matching commercial AWS endpoint. Other AWS partitions use their own endpoint suffixes.
Read current IAM credentials from a private qa_data/aws/dynamodb.json containing string fields access_key, secret_key, and, for temporary credentials, session_token. Prefer short-lived role credentials and refresh them before expiry. This code explicitly reads the file; it does not discover an AWS profile or refresh credentials automatically. The session token is included in the signed X-Amz-Security-Token query parameter, so keep request URLs and diagnostics private. A Socket explicitly enables TLS certificate verification and is supplied to Rest. Reuse the configured Rest object for subsequent requests.
Required IAM action: dynamodb:DescribeTable. Restrict access to the intended table ARN; an index query also needs the appropriate index ARN.
Checks transport completion, HTTP 200, and JSON validity separately. DynamoDB errors include __type and message. HTTP 400 can mean throttling, failed conditions, invalid input, or expired credentials. Use bounded exponential backoff with jitter for retryable failures; renew expired credentials. A failed condition requires an application decision, not an automatic retry. For writes with an uncertain outcome, read/reconcile before retrying. This sample does not automatically replay writes.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Credentials
string ls_Region
oleobject loo_Endpoint
oleobject loo_Aws
oleobject loo_Rest
oleobject loo_Connection
oleobject loo_Body
oleobject loo_Result
oleobject loo_RequestBody
oleobject loo_ResponseBody
string ls_TableName
oleobject loo_ErrorType
long i
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
// Private configuration, not a file in public web content or source control.
// Load current IAM credentials authorized for the DynamoDB operation.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_Credentials
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Credentials.Strict = 1
li_Success = loo_Credentials.LoadFile("qa_data/aws/dynamodb.json")
if li_Success <> 1 then
Write-Debug "Could not load private AWS credentials."
destroy loo_Credentials
return
end if
if (loo_Credentials.JsonTypeOf("access_key") <> 1) OR (loo_Credentials.StringOf("access_key") = "") then
Write-Debug "Missing or invalid access_key."
destroy loo_Credentials
return
end if
if (loo_Credentials.JsonTypeOf("secret_key") <> 1) OR (loo_Credentials.StringOf("secret_key") = "") then
Write-Debug "Missing or invalid secret_key."
destroy loo_Credentials
return
end if
// Set this once to the region containing the table.
ls_Region = "us-west-2"
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")
loo_Endpoint.Append("dynamodb.")
loo_Endpoint.Append(ls_Region)
loo_Endpoint.Append(".amazonaws.com")
loo_Aws = create oleobject
li_rc = loo_Aws.ConnectToNewObject("Chilkat.AuthAws")
loo_Aws.AccessKey = loo_Credentials.StringOf("access_key")
loo_Aws.SecretKey = loo_Credentials.StringOf("secret_key")
loo_Aws.Region = ls_Region
loo_Aws.ServiceName = "dynamodb"
loo_Aws.SignatureVersion = 4
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
li_Success = loo_Rest.SetAuthAws(loo_Aws)
if li_Success <> 1 then
Write-Debug "Could not configure AWS signing."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
return
end if
// Temporary IAM/STS credentials require their session token on every signed request.
// AddQueryParam includes it in SigV4's canonical query. Never log the request URL.
// Leave session_token absent or empty only for credentials that do not have one.
if loo_Credentials.HasMember("session_token") = 1 then
if loo_Credentials.JsonTypeOf("session_token") <> 1 then
Write-Debug "session_token must be a string."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
return
end if
if loo_Credentials.StringOf("session_token") <> "" then
li_Success = loo_Rest.AddQueryParam("X-Amz-Security-Token",loo_Credentials.StringOf("session_token"))
if li_Success <> 1 then
Write-Debug "Could not set the session-token parameter."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
return
end if
end if
end if
// Supply a Socket to explicitly enable TLS certificate verification.
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")
loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
Write-Debug "TLS connection failed; inspect diagnostics privately."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
return
end if
li_Success = loo_Rest.UseConnection(loo_Connection,1)
if li_Success <> 1 then
Write-Debug "Could not attach the TLS connection."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
return
end if
li_Success = loo_Rest.AddHeader("Content-Type","application/x-amz-json-1.0")
if li_Success <> 1 then
Write-Debug "Could not set the content type."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
return
end if
loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")
loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")
loo_Result.Strict = 1
loo_RequestBody = create oleobject
li_rc = loo_RequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_ResponseBody = create oleobject
li_rc = loo_ResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.AddHeader("X-Amz-Target","DynamoDB_20120810.DescribeTable")
if li_Success <> 1 then
Write-Debug "Could not set the DynamoDB operation."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
return
end if
ls_TableName = "ExampleItems"
loo_Body.UpdateString("TableName",ls_TableName)
// EmitSb appends. Clear the request buffer before each request/page.
loo_RequestBody.Clear()
li_Success = loo_Body.EmitSb(loo_RequestBody)
if li_Success <> 1 then
Write-Debug "Could not encode the request."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
return
end if
li_Success = loo_Rest.FullRequestSb("POST","/",loo_RequestBody,loo_ResponseBody)
if li_Success <> 1 then
Write-Debug "Request did not complete; inspect diagnostics privately."
// A write may already have succeeded. Reconcile its outcome before retrying.
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "DynamoDB HTTP status: " + string(loo_Rest.ResponseStatusCode)
li_Success = loo_Result.LoadSb(loo_ResponseBody)
if li_Success = 1 then
if loo_Result.JsonTypeOf("__type") = 1 then
loo_ErrorType = create oleobject
li_rc = loo_ErrorType.ConnectToNewObject("Chilkat.StringBuilder")
loo_ErrorType.Append(loo_Result.StringOf("__type"))
Write-Debug "AWS error type: " + loo_ErrorType.GetAsString()
end if
end if
// Throttling can be HTTP 400. Inspect __type, not just the HTTP status.
// Keep full error messages, item data, and signed request diagnostics private.
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType
return
end if
li_Success = loo_Result.LoadSb(loo_ResponseBody)
if li_Success <> 1 then
Write-Debug "Expected a well-formed JSON response."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType
return
end if
if (loo_Result.JsonTypeOf("Table.TableName") <> 1) OR (loo_Result.StringOf("Table.TableName") = "") then
Write-Debug "Missing or invalid Table.TableName."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType
return
end if
if (loo_Result.JsonTypeOf("Table.TableStatus") <> 1) OR (loo_Result.StringOf("Table.TableStatus") = "") then
Write-Debug "Missing or invalid Table.TableStatus."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType
return
end if
Write-Debug "Table: " + loo_Result.StringOf("Table.TableName")
Write-Debug "Status: " + loo_Result.StringOf("Table.TableStatus")
Write-Debug "ARN: " + loo_Result.StringOf("Table.TableArn")
if loo_Result.HasMember("Table.BillingModeSummary.BillingMode") = 1 then
Write-Debug "Billing mode: " + loo_Result.StringOf("Table.BillingModeSummary.BillingMode")
end if
// Counts and sizes can exceed int. Print their decimal representation as strings.
if loo_Result.HasMember("Table.ItemCount") = 1 then
Write-Debug "Approximate item count: " + loo_Result.StringOf("Table.ItemCount")
end if
if loo_Result.HasMember("Table.TableSizeBytes") = 1 then
Write-Debug "Approximate bytes: " + loo_Result.StringOf("Table.TableSizeBytes")
end if
if loo_Result.JsonTypeOf("Table.KeySchema") <> 4 then
Write-Debug "Expected KeySchema array."
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType
return
end if
i = 0
do while (i < loo_Result.SizeOfArray("Table.KeySchema"))
loo_Result.I = i
Write-Debug loo_Result.StringOf("Table.KeySchema[i].KeyType") + ": " + loo_Result.StringOf("Table.KeySchema[i].AttributeName")
i = i + 1
loop
// Optional index arrays may be absent.
i = 0
do while (i < loo_Result.SizeOfArray("Table.GlobalSecondaryIndexes"))
loo_Result.I = i
Write-Debug "Global index: " + loo_Result.StringOf("Table.GlobalSecondaryIndexes[i].IndexName") + "; status: " + loo_Result.StringOf("Table.GlobalSecondaryIndexes[i].IndexStatus")
i = i + 1
loop
i = 0
do while (i < loo_Result.SizeOfArray("Table.LocalSecondaryIndexes"))
loo_Result.I = i
Write-Debug "Local index: " + loo_Result.StringOf("Table.LocalSecondaryIndexes[i].IndexName")
i = i + 1
loop
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Body
destroy loo_Result
destroy loo_RequestBody
destroy loo_ResponseBody
destroy loo_ErrorType