Created
March 13, 2020 01:51
-
-
Save djg07/55e9498b2ed29e24b4440aac5f9183ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Thanks this is really helpful for me