Package: skymantle-boto-buddy
Skymantle Boto BuddyA wrappper for boto3 to access common aws severless services primarily used for aws Lambda. By default the wrapper is dependent on using boto3 configuration throughenvironment variablesfor setting credentials for accessing aws resources. It's also possible to provide aboto3.Sessionobject for setting credentials.When used within the context of an aws lambda function, no creditials are required and instances of boto3 resource and clients are created during lambda initialization when importing helpers. The library determines its running in the context of a lambda function but looking for theAWS_LAMBDA_FUNCTION_NAMEenvironment variable.The boto3 client and resource objects are cached but it is possible to also get uncached instances or cache can be disabled globally by setting theBOTO_BUDDY_DISABLE_CACHEenvironment variable. Supported values are1,true,yesandon.InstallationTo install use:pip3 install skymantle_boto_buddyUsingskymantle_boto_buddywill not include the boto3 dependency, useful when part of a lambda function and the lambda runtime version or a layer is used.  To include boto3 use:pip3 install skymantle_boto_buddy[boto3]UsageThe library provides the following functions.Packageget_boto3_clientget_boto3_resourceDynamoDbget_dynamodb_resourceget_tableput_item_simplifiedupdate_item_simplifiedget_itemdelete_itemquery_no_pagingS3get_s3_clientget_s3_resourceget_bucketget_object_signed_urlput_object_signed_urlget_objectget_object_bytesget_object_jsonget_object_csv_readerupload_fileobjput_objectdelete_objectdelete_objectscopylist_objects_v2execute_sql_query_simplifiedSSMget_ssm_clientget_parameterget_parameter_decryptedCloudFormationget_cloudformation_clientdescribe_stacksget_stack_outputsSTSget_sts_clientget_caller_identityget_caller_accountStepFunctionget_stepfunction_clientstart_executionstart_sync_executionstart_with_wait_for_completiondescribe_executionLogsget_logs_clientExamplesrunning inside a lambda function or using environment variable creditionalfromskymantle_boto_buddyimportdynamodbdynamodb.put_item_simplified("table_name",{"PK":"some_key","Description":"Some description"})providing a Session and specifiying a profile nameddeveloperfromboto3importSessionfromskymantle_boto_buddyimportdynamodbsession=Session(profile_name="developer")dynamodb.put_item_simplified("table_name",{"PK":"some_key","Description":"Some description"},session=session)Get a version of the s3 client that is not cachedfromboto3importSessionfromskymantle_boto_buddyimportEnableCache,s3s3_client=get_s3_client(enable_cache=EnableCache.NO)unit test a function with patching (also possible to use packages likemoto)# my_file.pyfromskymantle_boto_buddyimportdynamodbdefsome_function():# ...item=dynamodb.get_item("table_name",{"PK":"some_key"})returnitem# my_test.pyfromunittest.mockimportMagicMockimportpytestfrompytest_mockimportMockerFixtureimportmy_file@pytest.fixture()defmock_dynamodb(mocker:MockerFixture)->MagicMock:mock=mocker.patch("my_file.dynamodb")returnmockdeftest_some_function(mock_dynamodb):mock_dynamodb.get_item.return_value={"PK":"some_pk","Name":"some value"}result=my_file.some_function()assertresult=={"PK":"some_pk","Name":"some value"}Source Code Dev NotesThe following project commands are supported:make setup- Installs all dependencies ands creates virtual environmentmake unitTests- runs unit testsmake lintAndAnalysis- Runsruff,banditandblackmake build- Creates distribution