# Dynamo

### Setup

```python
import boto3
from botocore.config import Config

session = boto3.Session(
  aws_access_key_id='AAAAAAAAAAAAAAAA',
aws_secret_access_key='VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV',
)

config = Config(
    region_name = 'us-west-2', 
    retries = {
        'max_attempts': 10,
        'mode': 'standard'
    }
)

ddb_client = session.resource('dynamodb', config=config)
story_category_table = ddb_client.Table('StoryCategory-yyyyyyyyyyyyd3c6xquflibtu-prod')
```

### Get

```python
response = table.get_item(Key={'id': id})

if 'Item' in response:
  retrieved_item = response['Item']
  print("Retrieved Item:", retrieved_item)
else:
  print("Item not found")
```

### Insert

```python
category = {
  'id': str(uuid.uuid4()),
  'title': 'Thirst Trap',
}
    
try:
    response = story_category_table.put_item(Item=category)
    print("PutItem succeeded:", response)
except Exception as e:
    print("Error inserting item:", e)
```

### Update

```python
updated_attributes = {
    'attribute_to_update': 'new_value',
}

response = story_category_table.update_item(
    Key={'your_primary_key': story_category_key},
    UpdateExpression='SET ' + ', '.join([f'{key} = :{key}' for key in updated_attributes]),
    ExpressionAttributeValues={f':{key}': value for key, value in updated_attributes.items()},
    ReturnValues='ALL_NEW'  # Optional, specify if you want to get the updated item's attributes in the response
)

```

## Delete


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/all/python/packages/aws/dynamo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
