Skip to content

Instantly share code, notes, and snippets.

@mholmes-hs
mholmes-hs / QueryLSI.py
Last active May 28, 2020 19:44
Query Example DynamoDB LSI
import boto3
from boto3.dynamodb.conditions import Key
def query_data_with_lsi():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Posts')
response = table.query(
IndexName='user_name_subject',
@mholmes-hs
mholmes-hs / SetupLSI.py
Created May 28, 2020 19:41
Setup for DynamoDB LSI example
import boto3
from boto3.dynamodb.conditions import Key
def create_table_with_lsi():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='Posts',
KeySchema=[
{
@mholmes-hs
mholmes-hs / QueryGSI.py
Created May 28, 2020 19:08
Query example using GSI
import boto3
from boto3.dynamodb.conditions import Key
def query_data_with_gsi():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Employees')
response = table.query(
IndexName='email',
@mholmes-hs
mholmes-hs / SetupGSI.py
Last active May 28, 2020 20:12
Creates a DynamoDB table with GSI
import boto3
from boto3.dynamodb.conditions import Key
def create_table_with_gsi():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='Employees',
KeySchema=[
{
@mholmes-hs
mholmes-hs / RangeKeyFetch.py
Last active May 28, 2020 18:13
Fetching data with range key - DynamoDB
import boto3
from boto3.dynamodb.conditions import Key
def fetch_data_with_range():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Books')
resp = table.get_item(
Key={
@mholmes-hs
mholmes-hs / RangeKeySetup.py
Created May 28, 2020 17:31
Range key setup dynamoDB
import boto3
from boto3.dynamodb.conditions import Key
def create_table_with_range():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='Books',
KeySchema=[
{
@mholmes-hs
mholmes-hs / multiPartScan.py
Created May 28, 2020 17:07
Multi Part Scan on DynamoDB
import boto3
from boto3.dynamodb.conditions import Key
def multi_part_scan():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
response = table.scan()
result = response['Items']
@mholmes-hs
mholmes-hs / scanFirstLastName.py
Created May 28, 2020 16:52
Scan first and last names in DynamoDB
import boto3
from boto3.dynamodb.conditions import Key
def scan_first_and_last_names():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
resp = table.scan(ProjectionExpression="first_name, last_name")
@mholmes-hs
mholmes-hs / basicScan.py
Last active May 28, 2020 16:46
Basic scan DynamoDB
import boto3
from boto3.dynamodb.conditions import Key
def scan():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
resp = table.scan()
@mholmes-hs
mholmes-hs / createBunchOfRecords.py
Last active October 21, 2021 07:28
Creates a bunch of DynamoDB records
import boto3
from boto3.dynamodb.conditions import Key
def create_bunch_of_users():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
for n in range(3):
table.put_item(Item={