View a markdown version of this page

Best practices, monitoring, and troubleshooting PutRows - Amazon Simple Storage Service

Best practices, monitoring, and troubleshooting PutRows

Best practices

Throughput and file sizes

How well-sized the files that PutRows writes are depends on how much data the table receives and how your table is partitioned. S3 Tables buffer rows from every producer and commit them on a fixed interval.

  • High-throughput tables – When a table receives about its target file size of data every 30 seconds, S3 Tables write files that reach the target file size as data arrives.

  • Low-throughput tables – Below that rate, the files that S3 Tables commit on each interval are smaller than the table's target file size. S3 Tables compaction then combines these smaller files in the background.

  • Partitions – Tables with fewer partitions support higher PutRows throughput. Rows for each partition are written to separate files, so the more partitions your rows span, the less throughput the table supports and the smaller each file is. To get the highest throughput, use a partition spec with fewer partitions, for example partition by day instead of by hour, and avoid partitioning on high-cardinality columns.

Schema changes

To protect rows that PutRows has already accepted but not yet committed, S3 Tables commit those rows before a schema change takes effect. To change the schema of a table that PutRows writes to:

  1. Pause your producers.

  2. Wait for the buffered rows to be committed.

  3. Change the table's schema.

  4. Update your producers to match the new schema, and then resume them. PutRows recognizes the new schema within a few seconds.

When you update your producers, follow these guidelines:

  • Adding a column – Add it as an optional column, or give it a write-default value. If you add a required column without a write-default, PutRows rejects rows that don't include it.

  • Removing or renaming a column – Stop sending the column before you resume your producers. PutRows rejects rows that include a field that isn't a column in the table.

Each row must match the table's current schema. Column names are matched exactly, including case.

Checking a channel

GetChannel returns the state of a table's channel. Use it to see approximately how many accepted rows aren't committed yet, and whether the table's commits are healthy.

GetChannel response fields
Field Description
state The state of the channel: active, failing, or failed. For what each state means, see Channel states.
approximateNumberOfBufferedRows The approximate number of rows that PutRows accepted but S3 Tables haven't committed yet. This value is weakly consistent.
errorCode Why buffered rows aren't being committed. kms_key_disabled, kms_access_denied, and kms_key_not_found have causes that you can fix. internal_error means that S3 Tables hit an internal issue; S3 Tables retry the commit automatically, and no action is needed unless the error persists.
errorMessage A description of errorCode. Present only when errorCode is present. Don't parse this value.

Channel states

Channel states
State What it means What to do
active PutRows is accepting rows, and S3 Tables are committing them. No action needed.
failing PutRows is accepting rows, but S3 Tables can't currently commit them. If errorCode is a KMS error, fix the cause, for example by re-enabling the table's KMS key or restoring S3 Tables access to it. If errorCode is internal_error or absent, S3 Tables retry the commit automatically. If the channel stays in this state, contact AWS Support.
failed The channel has stopped. PutRows doesn't accept rows on this channel. Call GetChannel and review errorCode and errorMessage to find the cause.
deleting The channel is being deleted, for example because its table is being deleted. PutRows doesn't accept new rows. No action needed.
deleted The channel was deleted. PutRows doesn't accept rows on this channel. No action needed.

Monitoring and auditing PutRows

You can track ingestion health with Amazon CloudWatch metrics, and audit every PutRows request with AWS CloudTrail and server access logs.

  • Amazon CloudWatch metrics – S3 Tables publish PutRows metrics to CloudWatch so that you can monitor ingestion health for your tables. For example, you can create a CloudWatch alarm that notifies you when S3 Tables can't commit the rows that PutRows accepted for a table, and then call GetChannel to find the cause. PutRows metrics are provided for all tables that PutRows writes to; you don't need to turn on request metrics for the table bucket. For more information, see Monitoring metrics with Amazon CloudWatch.

  • AWS CloudTrail – PutRows requests are recorded as data events in AWS CloudTrail. To record them, configure a trail or event data store with S3 Tables data events enabled.

  • Server access logs – If server access logging is turned on for a table bucket, PutRows requests to the tables in that bucket are recorded in the bucket's server access logs. To turn on logging, use the PutTableBucketLogging operation or the Amazon S3 console. For more information, see Logging requests for S3 Tables using server access logging.

Errors and retries

PutRows errors
Error HTTP status code What to do
BadRequestException, ValidationException 400 The request is malformed or a row doesn't match the table's schema. For example, the rows are in a JSON array, the payload is empty, or the payload checksum is missing. Fix the request and resend it. Don't retry the same request unchanged.
SchemaValidationException 400 A row doesn't match the table's schema. Fix or remove the row and resend the request.
AccessDeniedException 403 The caller doesn't have the required permissions. Check the IAM policy.
NotFoundException 404 The channel doesn't exist yet. The default channel is created the first time that PutRows writes to the table.
InvalidStateException 409 The table's state changed while PutRows was processing the request. Retry the request.
TooManyRequestsException 429 The table or account is receiving more data or requests than it can accept. Retry with exponential backoff and jitter.
InternalServerErrorException 500 An internal error occurred. Retry with exponential backoff.
ServiceUnavailableException 503 The service is temporarily unavailable. Retry with exponential backoff and jitter.

Retries are safe because PutRows provides at-least-once delivery. If the original request wasn't accepted, the retry writes the rows. If the original request was accepted but you didn't receive the response, the retry writes the rows a second time, which you can remove with a unique key column at query time. The AWS SDKs retry 429, 500, and 503 errors automatically with their standard retry configuration. Retry 409 errors in your application.