Airflow Summit 2026 is coming August 31 - September 2 in Austin, TX. Register now to secure your spot!

airflow.providers.amazon.aws.hooks.dynamodb

This module contains the Amazon DynamoDB Hook.

Classes

DynamoDBHook

Interact with Amazon DynamoDB.

Module Contents

class airflow.providers.amazon.aws.hooks.dynamodb.DynamoDBHook(*args, table_keys=None, table_name=None, **kwargs)[source]

Bases: airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook

Interact with Amazon DynamoDB.

Provide thick wrapper around boto3.resource("dynamodb").

Parameters:
  • table_keys (list | None) – partition key and sort key

  • table_name (str | None) – target DynamoDB table

Additional arguments (such as aws_conn_id) may be specified and are passed down to the underlying AwsBaseHook.

table_keys = None[source]
table_name = None[source]
property client: botocore.client.BaseClient[source]

Return boto3 client.

write_batch_data(items)[source]

Write batch items to DynamoDB table with provisioned throughout capacity.

Parameters:

items (collections.abc.Iterable) – list of DynamoDB items.

get_import_status(import_arn)[source]

Get import status from Dynamodb.

Parameters:

import_arn (str) – The Amazon Resource Name (ARN) for the import.

Returns:

Import status, Error code and Error message

Return type:

tuple[str, str | None, str | None]

get_item(table_name, key)[source]

Retrieve a single item from a DynamoDB table by primary key.

Uses the boto3 resource API so keys and attribute values are plain Python types (str, int, Decimal, …) rather than the low-level typed format ({"S": "value"}).

Parameters:
  • table_name (str) – Name of the DynamoDB table.

  • key (dict[str, Any]) – Primary key of the item, e.g. {"pk": "value"} or {"pk": "value", "sk": "range_value"}.

Returns:

The item as a plain dict, or None if not found.

Return type:

dict[str, Any] | None

put_item(table_name, item, condition_expression=None)[source]

Insert or replace an item in a DynamoDB table.

Parameters:
  • table_name (str) – Name of the DynamoDB table.

  • item (dict[str, Any]) – Item attributes as a plain dict, e.g. {"pk": "value", "status": "pending"}.

  • condition_expression (str | None) – Optional condition expression string.

Returns:

The raw response from DynamoDB.

Return type:

dict[str, Any]

update_item(table_name, key, update_expression, expression_attribute_values, expression_attribute_names=None, condition_expression=None)[source]

Update attributes of an existing item in a DynamoDB table.

Uses the boto3 resource API so values are plain Python types.

Parameters:
  • table_name (str) – Name of the DynamoDB table.

  • key (dict[str, Any]) – Primary key of the item to update.

  • update_expression (str) – Update expression, e.g. "SET #s = :status, updated_at = :ts".

  • expression_attribute_values (dict[str, Any]) – Substitution values for the expression, e.g. {":status": "done", ":ts": "2024-01-01"}.

  • expression_attribute_names (dict[str, str] | None) – Optional name aliases for reserved words, e.g. {"#s": "status"}.

  • condition_expression (str | None) – Optional condition expression string.

Returns:

The updated item attributes, or None if the update returned no attributes.

Return type:

dict[str, Any] | None

delete_item(table_name, key, condition_expression=None)[source]

Delete an item from a DynamoDB table.

Parameters:
  • table_name (str) – Name of the DynamoDB table.

  • key (dict[str, Any]) – Primary key of the item to delete.

  • condition_expression (str | None) – Optional condition expression string.

Returns:

The deleted item’s attributes, or None if the item did not exist.

Return type:

dict[str, Any] | None

query(table_name, key_condition_expression, expression_attribute_values=None, expression_attribute_names=None, filter_expression=None, index_name=None, limit=None)[source]

Query items from a DynamoDB table or secondary index.

Uses the boto3 resource API so values are plain Python types. key_condition_expression accepts either a string expression or a boto3 boto3.dynamodb.conditions.ConditionBase object (e.g. Key("pk").eq("value")).

Parameters:
  • table_name (str) – Name of the DynamoDB table.

  • key_condition_expression (Any) – Key condition — string or boto3.dynamodb.conditions.ConditionBase.

  • expression_attribute_values (dict[str, Any] | None) – Substitution values (required when using string expressions, omit when using condition objects).

  • expression_attribute_names (dict[str, str] | None) – Optional name aliases for reserved words.

  • filter_expression (Any | None) – Optional filter applied after the query — string or boto3.dynamodb.conditions.ConditionBase.

  • index_name (str | None) – Name of a secondary index to query.

  • limit (int | None) – Maximum number of items to evaluate (see DynamoDB Limit semantics — this is not a guaranteed page size).

Returns:

List of matching items as plain dicts.

Return type:

list[dict[str, Any]]

Was this entry helpful?