Skip to content

Instantly share code, notes, and snippets.

View kennovation1's full-sized avatar

Ken Robbins kennovation1

View GitHub Profile
@kennovation1
kennovation1 / busmon.py
Last active August 23, 2021 16:07
Continuously monitor and pretty print Amazon EventBridge traffic as captured in CloudWatch Logs
# busmon.py
# Monitor CloudWatch Logs for EventBridge traffic.
#
# This script assumes that there is a Lambda function snooping an EventBridge bus
# and logging the events to a CloudWatch Logs group.
#
# Your format will likely be different and will require slight adjustments to the parsing
# logic below. The default format assumed for this version is:
# timestamp and other stuff|field|field|field|SNOOPED detail-type: <eventName> jsonString
# That is 5 pipe-delimited fields, where the last field is the only field used.
$ aws pinpoint get-apps
{
"ApplicationsResponse": {
"Item": [
{
"tags": {},
"Id": "APP_PROJECT_IDENTIFIER",
"Arn": "arn:aws:mobiletargeting:us-east-1:AWS_ACCOUNT_ID:apps/APP_PROJECT_IDENTIFIER",
"Name": "Example project name"
}
@kennovation1
kennovation1 / decimalencoder.py
Created May 2, 2019 20:58
Decimal encoder to use with json.dumps so that it handles Decimals (by converting them to floats)
class DecimalEncoder(json.JSONEncoder):
'''
An encoder for use with json.dumps when the dict contains Decimal type objects
such as are returned for DynamoDB number attributes.
Usage: json.dumps(someDict, cls=DecimalEncoder)
'''
def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
return super(DecimalEncoder, self).default(o)
@kennovation1
kennovation1 / ddb-global-attributes.json
Created May 2, 2019 20:53
Example of attributes the DynamoDB automatically adds when a table is configured as a global table
{
"aws:rep:deleting": {
"BOOL": false
},
"aws:rep:updateregion": {
"S": "us-east-1"
},
"aws:rep:updatetime": {
"N": "1554766902.780001"
}
@kennovation1
kennovation1 / ddbutils-excerpt.py
Last active May 6, 2019 14:55
Signature example for function to convert an existing table to a global DynamoDB table
'''
Utility function that wraps other utilities to run a pipeline that dumps data from existing table to an S3 file,
clears the table, configures the global table group, reloads the table from the backup
'''
success = enableGlobalTables(
'sourceTable': 'mySourceTable',
'sourceRegion': 'us-east-1',
'partitionKey': 'myPartKey',
'sortKey': None,
'backupBucket': 'myScratchBucket',