Package: aws_snippets
OverviewPython3 classes and functions to execute common AWS operations.Usage Example"""Read secret string from AWS Secrets Manager."""importaws_snippets# secret_string = aws_snippets.readsecret('<secret-ID>')secret_string=aws_snippets.readsecret('dkfjh765-sdfsf456-dfgd')print(secret_string)# Output: "I'm Batman!"Get Full Functionality List from DocstringPython Commands:importaws_snippetshelp(aws_snippets)BASH Commands:python-c'import aws_snippets; help(aws_snippets)'OutputHelponpackageaws_snippets:NAMEaws_snippets-ExecuteAWSoperations.PACKAGECONTENTSCLASSESbuiltins.objectWriteLogclassWriteLog(builtins.object)|WriteLog(text)||CreateJSONlogobjectforCloudWatch.||# Import modules.|importjson|fromaws_snippetsimportWriteLog||# Initiate with empty dictionary.|logger=WriteLog({})||# Collect entries to log.|logger.log('<strkey>','<value>')|logger.log('<intkey>',<value>)|logger.log('<boolkey>',<True/False>)||# Print out to CloudWatch as accumulated log.|print(json.dumps(logger.text))||Methodsdefinedhere:||__init__(self,text)|Initializelogcontent.||log(self,key,value)|Updatelogcontent.||----------------------------------------------------------------------|Datadescriptorsdefinedhere:||__dict__|dictionaryforinstancevariables(ifdefined)||__weakref__|listofweakreferencestotheobject(ifdefined)FUNCTIONSb64encode(cleartext:str,encoding:str='latin-1')->strEncodestringsusingBase64.returnstrcfpurge(cf_dist:str,path:str,call_ref:str)->dictCreateAmazonCloudFrontcacheinvalidation.returndictcleantmp(tmppath:str)->NoneCleanLambda/tmppath.returnNonedynamodbcreatetable(table:str,attrdictls:list,schemadictls:list,kmsid:str,tagdictls:list)->NoneCreateatableinDynamoDB.returnNonedynamodbdeleteallitems(table:str)->NoneDeleteallitemsfromaDynamoDBtable.returnNonedynamodbdeletetable(table:str)->NoneDeleteatablefromDynamoDB.returnNonedynamodbgetitem(table:str,key:str,value:str)->dictGetasingleitemfromDynamoDB.returndictdynamodbputitem(table:str,itemdict:dict)->NonePutasingleitemintoDynamoDB.returnNonedynamodbqueryitems(table:str,key:str,value:str)->dictGetitemsbasedonkeywordqueryfromDynamoDB.returndictdynamodbscanallitems(table:str)->dictGetallitemsfromatableinDynamoDB.returndictdynamodbscanitems(table:str,key:str,value:str,patternexp:dict)->dictGetallitemsfromaDynamoDBtablethenfilterbyexpression.returndictdynamodbupdateitem(table:str,keydict:dict,attributedict:dict,valuedict:dict,updateexpression:str)->dictUpdateaniteminaDynamoDBtable.returndicthttpget(url:str,headers:dict={},encoding:str='latin-1')->dictMakeHTTPrequestsusingGETmethod.returndicthttppost(url:str,headers:dict={},data:dict={},encoding:str='latin-1')->strMakeHTTPrequestsusingPOSTmethod.returnstrkmsdecrypt(ciphertext:str,kmsid:str)->strDecryptstringsusingAWSKMS.returnstrkmsencrypt(cleartext:str,kmsid:str)->strEncryptstringsusingAWSKMS.returnstrrandomize(length:int,punctuations:bool=False)->strCreaterandomstrings.returnstrreadsecret(id:str)->strReadsecretvaluesinAWSSecretsManager.returnstrsanitizerclean(input:str)->strSanitizeinputitems.returnstrsanitizercleanlist(input:list,pattern:str)->listSanitizeinputlist.returnlistsanitizercleanurl(url:str)->strSanitizeinputURLs.returnstrsanitizercleanurllist(input:list,pattern:str)->listSanitizeinputlist.returnlistsanitizervalidate(input:str,pattern:str)->boolValidateinputitemstoRegExpatterns.returnboolsanitizervalidatelist(input:list)->boolValidateinputlist.returnboolsha3512hash(clrtxt:str,condiments:str,encoding:str='latin-1')->strHashstringsusingSHA3_512algorithm.returnstrsnsnotify(topic:str,message:str,subject:str)->NoneSendAWSSNSnotifications.returnNonesqsmessage(queue_url:str,message:dict)->dictSendmessagesintoAWSSQSqueues.returndictDATAUnion=typing.UnionUniontype;Union[X,Y]meanseitherXorY.Todefineaunion,usee.g.Union[int,str].Details:-Theargumentsmustbetypesandtheremustbeatleastone.-Noneasanargumentisaspecialcaseandisreplacedbytype(None).-Unionsofunionsareflattened,e.g.::Union[Union[int,str],float]==Union[int,str,float]-Unionsofasingleargumentvanish,e.g.::Union[int]==int# The constructor actually returns int-Redundantargumentsareskipped,e.g.::Union[int,str,int]==Union[int,str]-Whencomparingunions,theargumentorderisignored,e.g.::Union[int,str]==Union[str,int]-Youcannotsubclassorinstantiateaunion.-YoucanuseOptional[X]asashorthandforUnion[X,None].VERSION2024.1.0.0FILE/Users/abdahmad/Desktop/aws_snippets/__init__.py