-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for adding in an event bus
- Loading branch information
Showing
7 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/events.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Standardised class for pushing events from within the ADF Namespace | ||
""" | ||
|
||
|
||
import os | ||
import boto3 | ||
|
||
|
||
class ADFEvents: | ||
def __init__( | ||
self, client: boto3.client, service, namespace="ADF", eventbus_arn=None | ||
) -> None: | ||
""" | ||
Client: Any Boto3 EventBridge client | ||
Service: The name of the Service e.g AccountManagement.EnableSupport | ||
namespace: Defaults to ADF | ||
eventbus_arn: Optionally specify a custom EventBridge ARN. If no ARN is specified, and no ENV variable set, will default to ADF-Event-Bus | ||
""" | ||
self.events = client | ||
self.source = f"{namespace}.{service}" | ||
self.eventbus_arn = ( | ||
os.environ.get("ADF_EVENTBUS_ARN", "ADF-Event-Bus") | ||
if eventbus_arn is None | ||
else eventbus_arn | ||
) | ||
|
||
# This dict isn't mutated. So it's safe to default to this | ||
def put_event(self, detailType, detail, resources=[]): # pylint: disable=W0102 | ||
payload = { | ||
"Source": self.source, | ||
"Resources": resources, | ||
"DetailType": detailType, | ||
"Detail": detail, | ||
"EventBusName": self.eventbus_arn, | ||
} | ||
trace_id = os.getenv("_X_AMZN_TRACE_ID") | ||
if trace_id: | ||
payload["TraceHeader"] = trace_id | ||
self.events.put_events(Entries=[payload]) |
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