Accessing the infrastructure
import boto3
import os
def main():
region_name = os.getenv('AWS_REGION')
table_name = os.getenv('AWS_DYNAMODB_TABLE_NAME')
dynamodb = boto3.resource("dynamodb", region_name=region_name)
table = dynamodb.Table(table_name)
test_item = {
"id": "test-id-1",
"Data": "Hello from the project!"
}
table.put_item(Item=test_item)
print(f"Successfully wrote item to {table_name}: {test_item}")
response = table.get_item(Key={"id": "test-id-1"})
item = response.get("Item")
if item:
print(f"Successfully read item from {table_name}: {item}")
else:
print(f"No item found in {table_name}")
if __name__ == "__main__":
main()Last updated