Skip to content

Conversation

@igorlg
Copy link
Contributor

@igorlg igorlg commented Sep 13, 2023

Summary

Unicorn Properties v2! This is an entire architecture and code structure overhaul, while keeping the same API and Event contracts, as well as workflow functionality.

Changes

Coupling between services was reduced considerably. Now, each service owns their EventBus, where events are produced to and consumed from. For cross-service event exchange - e.g. Service A wants to listen to events from Service B - service A creates a EventBus rule on Service B's bus, to send matched events to Service A's bus.
This means the only inter-service resources are EventBridge Rules, and those are isolated in CloudFormation stacks defined in <service>/integration/subscriptions.yaml.

The SAM config file in each service was also refactored from toml to yaml.

Contracts Service

  • Joined create and update contract functionality into a single Lambda function ContractEventHandler
  • /contracts API Gateway now queues requests in SQS, which are then processed by ContractEventHandler function
  • ContractStatusChanged events are now generated by EventBridge Pipes, from DynamoDB Streams changes. (see Appendix 1 below)
  • Events are produced to and consumed from UnicornContractsEventBus
  • API Gateway schema is now maintained as OpenAPI Spec file api.yaml and used to define the API in UnicornContractsApi

Properties Service

  • Events are produced to and consumed from UnicornPropertiesEventBus
  • Consume ContractStatusChanged events from Contracts Service via EB Rule
  • Consume PublicationApprovalRequested events from Web Service via EB Rule

Web Service

  • /request_approval API Gateway now queues requests in SQS, which are then processed by RequestApproval function
  • Consume PublicationEvaluationCompleted events from Properties service via EB Rule
  • API Gateway schema is now maintained as OpenAPI Spec file api.yaml and used to define the API in UnicornWebApi

Shared Components

  • Each service now has their own Schema Registry, defined under <service>/integration/event-schemas.yaml
  • SSM Parameters Unicorn{Contracts|Properties|Web}Namespace are now defined in the uni-prop-{Stage}-stack, as they are referenced across all services.

User experience

User experience is the same, no differences in workflow or API contracts/endpoints.

Appendix 1

Why introduce EventBridge Pipes? This was designed to avoid a possible 'distributed transaction' failure, where the ContractEventHandler function could persiste a change in DynamoDB and then fail to post the event to EventBridge, or vice versa.

To avoid complex checks and error handling, we decided to streamline the process in such a way that each component only has one job. This way, partial errors are removed entirely and can be handled much more easily.

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

igorlg added 30 commits August 24, 2023 11:15
igorlg and others added 15 commits September 11, 2023 20:01
* chore: remove unused code and forgotten comments

* chore: reorder ENV vars; make LambdaContext mock generic to fit all functions

* chore: lint Python files

* test: add tracer and logger output on propertes_approval_sync_function methods

* chore: reformat StateMachine ASL file

* fix: update Stage name in shared stack

* chore: renamed stack file for unicorn_shared
@igorlg igorlg added service/contracts Related to Contracts Service service/properties Related to Properties Service service/web Related to Properties Web labels Sep 13, 2023
@igorlg igorlg requested a review from a team as a code owner September 13, 2023 22:49
@igorlg igorlg self-assigned this Sep 13, 2023
@github-actions
Copy link

No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.

@github-actions github-actions bot added do-not-merge PRs that are blocked for varying reasons need-issue PR is missing a related issue for tracking change enhancement New feature or request labels Sep 13, 2023
@igorlg igorlg requested a review from sliedig September 13, 2023 23:49
@igorlg igorlg merged commit c32c393 into develop Sep 14, 2023
@github-actions
Copy link

undefined No related issues found. Please ensure 'pending-release' label is applied before releasing.

sliedig added a commit that referenced this pull request Nov 7, 2025
* chore: Converted SAM Config file from TOML to YAML using samp-cli

* feat: Updated template for new Contracts service implementation model

* chore: add API contract

* chore: Refactored integration tests

* chore: Updated unit tests, et al

* feat: Add EB Pipes

* bug: remove file added by mistake

* feat: Refactored unicorn_web

* chore: Implemented final Unit tests for unicorn_contracts

* test: Fixed all unit, integration and Curl tests for unicorn_contracts

* chore: add missing licensing header

* chore: typos and file styling

* fix: remote unused test file, fixed naming convention of subscriber EB Policy

* chore: remove unused coverage file

* feat: Updated unicorn_web to v2 architecture, implemented integration and Curl tests

* fix: remove curl-test from make test alias

* chore: remove unused swagger-cli from make build

* chore: Update Python dependencies on unicorn_properties

* chore: remove Coverage config, add Integration tests to pyproject in unicorn_properties

* chore: replace samconfig file from TOML to YAML

* feat: Add EventBridge subscribers and subscription rules to unicorn_properties

* chore: move state machine definition out of src/ to match across runtimes

* chore: update template section name comments

* chore: update cfn-lint ignored rules

* chore: linted/inlined intrinsic functions for better readability

* feat: add local EB bus to unicorn_properties, replace hard-coded service namespace with mapped constant

* feat: add EB SSM Params to unicorn_properties

* chore: add missing DDB permissions, remove unused SQS permission from unicorn_properties lambda functions

* chore: lint unicorn_properties template, change EB trigger rule for ContractStatusChangedFunction

* chore: fix EventBus name, lint JSON files in unicorn_properties eventbridge event payloads

* chore: replace hardcoded stack name from Makefile with YQ command to read from samconfig

* chore: lint and document Makefile stage groups

* test: add Integration tests scaffold

* chore: Add SAM validate to Makefile build stage

* chore: remove unecessary SAM command line argument from build stage - settings are enforced in samconfig.yaml

* chore: lint JSON files, remove unused JSON event payloads

* bug: fix EB catch-all rule pattern match, add naming to EB catch-all CW Logs group, removed unused cfn-lint ignore rule

* feat: Split event schemas and registry to each service

* chore: Add license header to state_machine definition

* fix: moved schema for PublicationEvaluationCompleted event from unicorn_web to unicorn_properties

* chore: minor changes to templates

* fix: renamed unicorn_web namespace in unicorn_properties schema library

* refactor: extracted property_id parsing into its own method

* refactor: removed DB update stage from approval function, and removed PENDING state from flow

* feat: Split event schemas and registry to each service

* chore: Add license header to state_machine definition

* fix: moved schema for PublicationEvaluationCompleted event from unicorn_web to unicorn_properties

* fix: renamed unicorn_web namespace in unicorn_properties schema library

* refactor: extracted property_id parsing into its own method

* refactor: removed DB update stage from approval function, and removed PENDING state from flow

* feat: updating Stage values to lowercase;
updating stage references and parameters;
sync with dotnet

* chore: Fix naming structures, move ServiceNamespace SSM param to SharedInfra

* feat: Add shared stack to Python implementation

* bug: Fix catch-all rule from each service to match events from every service source

* chore: remove top-level section comments from templates

* chore: update Python dependencies

* chore: remove unused PyTest Coverage tool

* chore: fix typos and misnomers in template comments

* chore: add description comments to template resources

* chore: add comments to resources and cfn-lint rules in template.yaml

* chore: reordered resources in template.yaml to improve readability

* chore: removed unused outputs

* chore: lambda function outputs - added ARN output, renamed Name output

* chore: reordered and fixed StateMachine policy templates

* chore: Uncommented StateMachine event trigger, as dependency with unicorn_web Namespace SSM param was removed

* chore: add missing Outputs for CatchAll CW Logs group

* chore: add missing OnFailure SQS destination

* bug: replaces status=NEW for PENDING on test DDB items, as per new architecture

* chore: remove commented-out Event payload

* chore: minor changes to template formatting (#39)

* chore: minor changes to template formatting

* chore: additional template updates and changes to subscriptions

* chore: additional template updates and changes to subscriptions

* fix: updated rule name

* fix: updated rule names

* update dependencies (#41)

* chore: update Python dependency versions

* chore: lint pyproject files, fix typo in description

* chore: bump code version in pyproject to match v2 tag

* test: reorganised test events, refactored unit tests

* nested stacks (#42)

* refactor: Moved each services ancillary stacks to be nested inside template.yaml, to simplify CI/CD deployment

* chore: fix template.yaml linting

* test: add outputs that help with integration tests

* chore: add description and comments to template.yaml sections

* fix: typo in SAM policy template usage

* test: reorganised test events, refactored unit tests

* Lint code (#43)

* chore: remove unused code and forgotten comments

* chore: reorder ENV vars; make LambdaContext mock generic to fit all functions

* chore: lint Python files

* test: add tracer and logger output on propertes_approval_sync_function methods

* chore: reformat StateMachine ASL file

* fix: update Stage name in shared stack

* chore: renamed stack file for unicorn_shared

* contract -> contracts

* contract->contracts tests

* test: remove partially-implemented Integration tests

* chore: Bring files inline with Dotnet, Java and Typescript

* test: fixing EventBus name in PublicationEvaluationCompleted event payload of unicorn_web

* bug: wrong Event source filter parameter in unicorn_web subscriptions

* chore: add log statements in unicorn_web's request_approval_function for publish_event

* bug: remove message attribute HttpMethod filter

* bug: unicorn_web requestApproval should only filter out properties in APPROVED state

* refactor: add schema package to pyproject

* chore: add missing global env var to unicorn_web, to bring it inline with other languages

* bug: wrong parameter being used for unicorn_web's PublicationApprovedEventHandlerFunction

* refactor: change CodeUri of all Lambda functions in unicorn_web to be src/. This is to fix Pythons import paths

* docs: add API Gateway CW Logs group tag

---------

Co-authored-by: Stephen Liedig <sliedig@amazon.com>
Co-authored-by: Kevin Chan <kevinwochan@gmail.com>
Co-authored-by: kechn <kechn@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge PRs that are blocked for varying reasons enhancement New feature or request need-issue PR is missing a related issue for tracking change service/contracts Related to Contracts Service service/properties Related to Properties Service service/web Related to Properties Web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants