Last active
March 13, 2019 03:57
-
-
Save reecestart/e94d541d4d4f57d058e31814da3e9463 to your computer and use it in GitHub Desktop.
Create, List and Delete SimpleDB Domains with Python
This file contains hidden or 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 | |
client = boto3.client('sdb') | |
def main(): | |
print("...") | |
def createSimpleDBDomain(): | |
choice = input("Do you want to create a SimpleDB Domain? Yes [1], No [2] ") | |
if choice == '2': | |
return | |
elif choice == '1': | |
SimpleDBDomainName = input("Name of SimpleDB Domain to create? ") | |
response = client.create_domain( | |
DomainName = SimpleDBDomainName | |
) | |
SimpleDBRequestId = response['ResponseMetadata']['RequestId'] | |
SimpleDBBoxUsage = response['ResponseMetadata']['BoxUsage'] | |
print("SimpleDB Create Request ID: " + SimpleDBRequestId + " complete for Box Usage: " + SimpleDBBoxUsage) | |
else: | |
return | |
class DomainDetails: | |
def listSimpleDBDomains(self): | |
print("Listing SimpledDB Domains") | |
response = client.list_domains( | |
) | |
self.domainNames = response['DomainNames'] | |
return self.domainNames | |
def listDomainMetadata(self,domainNames): | |
for domainName in domainNames: | |
response = client.domain_metadata( | |
DomainName=domainName | |
) | |
ItemCount = response['ItemCount'] | |
ItemNamesSizeBytes = response['ItemNamesSizeBytes'] | |
AttributeNameCount = response['AttributeNameCount'] | |
AttributeNamesSizeBytes = response['AttributeNamesSizeBytes'] | |
AttributeValueCount = response['AttributeValueCount'] | |
AttributeValuesSizeBytes = response['AttributeValuesSizeBytes'] | |
print(domainName + " has " + str(ItemCount) + " items for " + str(ItemNamesSizeBytes) + " bytes.") | |
print(domainName + " has " + str(AttributeNameCount) + " names for " + str(AttributeNamesSizeBytes) + " bytes.") | |
print(domainName + " has " + str(AttributeValueCount) + " attributes for " + str(AttributeValuesSizeBytes) + " bytes.") | |
def deleteSimpleDBDomain(): | |
choice = input("Do you want to delete a SimpleDB Domain? Yes [1], No [2] ") | |
if choice == '2': | |
return | |
elif choice == '1': | |
SimpleDBDomainName = input("Name of SimpleDB Domain to delete? ") | |
response = client.delete_domain( | |
DomainName = SimpleDBDomainName | |
) | |
SimpleDBRequestId = response['ResponseMetadata']['RequestId'] | |
SimpleDBBoxUsage = response['ResponseMetadata']['BoxUsage'] | |
print("SimpleDB Delete Request ID: " + SimpleDBRequestId + " complete for Box Usage: " + SimpleDBBoxUsage) | |
else: | |
return | |
if __name__ == '__main__': | |
main() | |
createSimpleDBDomain() | |
dd = DomainDetails() | |
dd.listSimpleDBDomains() | |
dd.listDomainMetadata(dd.domainNames) | |
deleteSimpleDBDomain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment