Skip to content

Instantly share code, notes, and snippets.

@djg07
Created March 13, 2020 01:51
Show Gist options
  • Save djg07/55e9498b2ed29e24b4440aac5f9183ba to your computer and use it in GitHub Desktop.
Save djg07/55e9498b2ed29e24b4440aac5f9183ba 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()
@PrasaDesk
Copy link

Thanks this is really helpful for me

@Leorfk
Copy link

Leorfk commented May 5, 2021

Thanks for your source code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment