airflow.providers.amazon.aws.hooks.dynamodb¶
This module contains the Amazon DynamoDB Hook.
Classes¶
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.AwsBaseHookInteract with Amazon DynamoDB.
Provide thick wrapper around
boto3.resource("dynamodb").- Parameters:
Additional arguments (such as
aws_conn_id) may be specified and are passed down to the underlying AwsBaseHook.- 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_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"}).See also
- put_item(table_name, item, condition_expression=None)[source]¶
Insert or replace an item in a DynamoDB table.
See also
- Parameters:
- Returns:
The raw response from DynamoDB.
- Return type:
- 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.
See also
- Parameters:
table_name (str) – Name of the DynamoDB table.
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
Noneif the update returned no attributes.- Return type:
- delete_item(table_name, key, condition_expression=None)[source]¶
Delete an item from a DynamoDB table.
See also
- Parameters:
- Returns:
The deleted item’s attributes, or
Noneif the item did not exist.- Return type:
- 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_expressionaccepts either a string expression or a boto3boto3.dynamodb.conditions.ConditionBaseobject (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
Limitsemantics — this is not a guaranteed page size).
- Returns:
List of matching items as plain dicts.
- Return type: