Skip to content

Instantly share code, notes, and snippets.

@hazdik
Forked from djg07/ddbLocal.py
Created December 22, 2020 06:40
Show Gist options
  • Save hazdik/64dabdbcbb90c42cb8c29bc6202077c2 to your computer and use it in GitHub Desktop.
Save hazdik/64dabdbcbb90c42cb8c29bc6202077c2 to your computer and use it in GitHub Desktop.
import boto3
def main():
# 1 - Create Client
ddb = boto3.resource('dynamodb',
endpoint_url='http://localhost:8000',
region_name='dummy',
aws_access_key_id='dummy',
aws_secret_access_key='dummy')
# 2 - Create the Table
ddb.create_table(TableName='Transactions',
AttributeDefinitions=[
{
'AttributeName': 'TransactionId',
'AttributeType': 'S'
}
],
KeySchema=[
{
'AttributeName': 'TransactionId',
'KeyType': 'HASH'
}
],
ProvisionedThroughput= {
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
print('Successfully created Table')
table = ddb.Table('Transactions')
input = {'TransactionId': '9a0', 'State': 'PENDING', 'Amount': 50}
#3 - Insert Data
table.put_item(Item=input)
print('Successfully put item')
#4 - Scan Table
scanResponse = table.scan(TableName='Transactions')
items = scanResponse['Items']
for item in items:
print(item)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment