Skip to content
Latchkey

aws dynamodb put-item: Write to DynamoDB in CI

Insert or replace a single item in a DynamoDB table.

aws dynamodb put-item writes one item, replacing any existing item with the same key. Attributes use DynamoDB's typed JSON ({"S":"..."}). In CI it seeds test data, writes deploy markers, or feeds integration test fixtures.

Common flags

  • --table-name - the target table (required)
  • --item - the typed-JSON item to write (required)
  • --condition-expression - only write if a condition holds (e.g. avoid overwrite)
  • --cli-input-json file://item.json - supply the whole request from a file

Example in CI

Seed a fixture row, refusing to overwrite an existing key.

shell
aws dynamodb put-item --table-name fixtures --item '{"id":{"S":"seed-1"},"name":{"S":"demo"}}' --condition-expression "attribute_not_exists(id)"

Common errors in CI

  • An error occurred (ConditionalCheckFailedException) - the condition-expression was not met
  • An error occurred (ResourceNotFoundException) - table name wrong or in another region
  • An error occurred (ValidationException) - missing key attribute or wrong typed-JSON shape
  • An error occurred (AccessDeniedException) - role lacks dynamodb:PutItem

Key takeaways

  • Items use typed JSON like {"S":"text"} or {"N":"1"}.
  • put-item replaces the whole item; use --condition-expression to guard overwrites.
  • ConditionalCheckFailedException is expected behavior when a guard blocks a write.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →