{"id":18573154,"url":"https://github.com/localstack-samples/sample-loan-broker-stepfunctions-lambda","last_synced_at":"2025-04-10T07:31:53.332Z","repository":{"id":154236786,"uuid":"631986971","full_name":"localstack-samples/sample-loan-broker-stepfunctions-lambda","owner":"localstack-samples","description":"Loan Broker application using Step Functions, DynamoDB, Lambda, SQS, and SNS.","archived":false,"fork":false,"pushed_at":"2025-01-14T12:44:42.000Z","size":2069,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-03-24T18:06:35.730Z","etag":null,"topics":["aws","developer-hub","dynamodb","lambda","localstack","localstack-developer-hub","sns","sqs","step-functions"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localstack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-24T13:29:27.000Z","updated_at":"2025-02-17T18:36:41.000Z","dependencies_parsed_at":"2025-01-14T13:38:26.996Z","dependency_job_id":"beae20c9-dd48-415e-bf98-fa5dcf271dd6","html_url":"https://github.com/localstack-samples/sample-loan-broker-stepfunctions-lambda","commit_stats":null,"previous_names":["localstack-samples/sample-loan-broker-stepfunctions-lambda"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-loan-broker-stepfunctions-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-loan-broker-stepfunctions-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-loan-broker-stepfunctions-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-loan-broker-stepfunctions-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localstack-samples","download_url":"https://codeload.github.com/localstack-samples/sample-loan-broker-stepfunctions-lambda/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248176395,"owners_count":21060059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","developer-hub","dynamodb","lambda","localstack","localstack-developer-hub","sns","sqs","step-functions"],"created_at":"2024-11-06T23:08:13.921Z","updated_at":"2025-04-10T07:31:52.975Z","avatar_url":"https://github.com/localstack-samples.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loan Broker application with AWS Step Functions, DynamoDB, Lambda, SQS, and SNS\n\n| Key          | Value                                                                                 |\n| ------------ | ------------------------------------------------------------------------------------- |\n| Environment  | \u003cimg src=\"https://img.shields.io/badge/LocalStack-deploys-4D29B4.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAKgAAACoABZrFArwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALbSURBVHic7ZpNaxNRFIafczNTGIq0G2M7pXWRlRv3Lusf8AMFEQT3guDWhX9BcC/uFAr1B4igLgSF4EYDtsuQ3M5GYrTaj3Tmui2SpMnM3PlK3m1uzjnPw8xw50MoaNrttl+r1e4CNRv1jTG/+v3+c8dG8TSilHoAPLZVX0RYWlraUbYaJI2IuLZ7KKUWCisgq8wF5D1A3rF+EQyCYPHo6Ghh3BrP8wb1en3f9izDYlVAp9O5EkXRB8dxxl7QBoNBpLW+7fv+a5vzDIvVU0BELhpjJrmaK2NMw+YsIxunUaTZbLrdbveZ1vpmGvWyTOJToNlsuqurq1vAdWPMeSDzwzhJEh0Bp+FTmifzxBZQBXiIKaAq8BBDQJXgYUoBVYOHKQRUER4mFFBVeJhAQJXh4QwBVYeHMQJmAR5GCJgVeBgiYJbg4T8BswYPp+4GW63WwvLy8hZwLcd5TudvBj3+OFBIeA4PD596nvc1iiIrD21qtdr+ysrKR8cY42itCwUP0Gg0+sC27T5qb2/vMunB/0ipTmZxfN//orW+BCwmrGV6vd63BP9P2j9WxGbxbrd7B3g14fLfwFsROUlzBmNM33XdR6Meuxfp5eg54IYxJvXCx8fHL4F3w36blTdDI4/0WREwMnMBeQ+Qd+YC8h4g78wF5D1A3rEqwBiT6q4ubpRSI+ewuhP0PO/NwcHBExHJZZ8PICI/e73ep7z6zzNPwWP1djhuOp3OfRG5kLROFEXv19fXP49bU6TbYQDa7XZDRF6kUUtEtoFb49YUbh/gOM7YbwqnyG4URQ/PWlQ4ASllNwzDzY2NDX3WwioKmBgeqidgKnioloCp4aE6AmLBQzUExIaH8gtIBA/lFrCTFB7KK2AnDMOrSeGhnAJSg4fyCUgVHsolIHV4KI8AK/BQDgHW4KH4AqzCQwEfiIRheKKUAvjuuu7m2tpakPdMmcYYI1rre0EQ1LPo9w82qyNziMdZ3AAAAABJRU5ErkJggg==\"\u003e \u003cimg src=\"https://img.shields.io/badge/AWS-deploys-F29100.svg?logo=amazon\"\u003e                                                                     |\n| Services     | Step Functions, SQS, SNS, Lambda, DynamoDB, EventBridge                                 |\n| Integrations | CDK, AWS CLI                                                                            |\n| Categories   | Serverless; Event-Driven architecture                                                   |\n| Level        | Intermediate                                                                            |\n| GitHub       | [Repository link](https://github.com/localstack/loan-broker-stepfunctions-lambda-app)   |\n\n## Introduction\n\nThe Loan Broker application with AWS Step Functions, DynamoDB, Lambda, SQS, and SNS demonstrates Gregor Hohpe's [Loan Broker example](https://www.enterpriseintegrationpatterns.com/ramblings/loanbroker_stepfunctions.html). The sample application implements a [Recipient List](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RecipientList.html) pattern and a [Scatter Gather](https://www.enterpriseintegrationpatterns.com/patterns/messaging/BroadcastAggregate.html) pattern to retrieve a list of banks and dynamically route loan application to multiple banks respectively. The sample application implements the following integration among the various AWS services:\n\n- User submits a loan application with personal data, desired terms, loan amount, and duration.\n- Loan Broker fetches information from Credit Bureau and adds it to the loan application submitted earlier.\n- Loan Broker routes the application to multiple banks, and the banks reply if they are willing to offer.\n- Loan Broker aggregates all the result(s) and returns the result(s) to the user.\n\nUsers can deploy this application on LocalStack and AWS with no changes using Cloud Development Kit (CDK). To test this application sample, we will demonstrate how you use LocalStack to deploy the infrastructure on your developer machine and your CI environment.\n\n## Architecture diagram\n\nThe following diagram shows the architecture that this sample application builds and deploys:\n\n![Architecture diagram for Loan Broker application with AWS Step Functions, DynamoDB, Lambda, SQS, and SNS](./images/architecture-diagram.png)\n\n- [Step Functions](https://docs.localstack.cloud/user-guide/aws/stepfunctions/) to controls the sequence of activities and transfer data between components for the Loan Broker.\n- [Lambda](https://docs.localstack.cloud/user-guide/aws/lambda/) functions to implement the business logic for the Loan Broker, Banks and Aggregator in the application.\n- [SNS](https://docs.localstack.cloud/user-guide/aws/sns/) to publish messages and broadcasts loan quote requests to any subscribing banks.\n- [SQS](https://docs.localstack.cloud/user-guide/aws/sqs/) to ferry loan quotes from the banks to the Aggregator.\n- [DynamoDB](https://docs.localstack.cloud/user-guide/aws/dynamodb/) as a key-value and document database to persist the Aggregator's state.\n\n## Prerequisites\n\n- LocalStack Pro with the [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli).\n- [Cloud Development Kit](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://www.npmjs.com/package/aws-cdk-local) installed.\n- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) with the [`awslocal` wrapper](https://docs.localstack.cloud/user-guide/integrations/aws-cli/#localstack-aws-cli-awslocal).\n- [Node.js](https://nodejs.org/en/download), and [`yarn`](https://yarnpkg.com/).\n\nStart LocalStack Community edition:\n\n```shell\nDEBUG=1 localstack start\n```\n\nWe specified DEBUG=1 to get the printed LocalStack logs directly in the terminal to help us see the event-driven architecture in action. If you prefer running LocalStack in detached mode, you can add the `-d` flag to the `localstack start` command, and use Docker Desktop to view the logs.\n\n## Instructions\n\nYou can build and deploy the sample application on LocalStack by running our `Makefile` commands. To deploy the infrastructure, you can run `make deploy` after installing the application dependencies, and run the test steps manually. Here are instructions to deploy and test it manually step-by-step.\n\n### Deploying the application\n\nTo create the AWS infrastructure locally, you can use CDK and our `cdklocal` wrapper. Before you can deploy the infrastructure, you need to install the application dependencies:\n\n```sh\nyarn\n```\n\nTo deploy the infrastructure, you can run the following command:\n\n```sh\ncdklocal bootstrap\ncdklocal deploy --all\n```\n\nThis will deploy the `LoanBroker-RecipientList-Stack` and `LoanBroker-PubSub-Stack` stacks. You will see the following output:\n\n```sh\nOutputs:\nLoanBroker-RecipientList-Stack.LoanBrokerArn = arn:aws:states:us-east-1:000000000000:stateMachine:LoanBroker-RecipientList-Stack-LoanBroker641FC9A8-dd79232c\nStack ARN:\narn:aws:cloudformation:us-east-1:000000000000:stack/LoanBroker-RecipientList-Stack/e7929928\n```\n\nTake a note of the `LoanBroker-RecipientList-Stack.LoanBrokerArn` output. You will need it to test the application.\n\n## Testing the application\n\nBefore you can test the application, you need to pre-populate the `LoanBrokerBanksTable` for the `RecipientsList` stack:\n\n```sh\nawslocal dynamodb put-item \\\n    --table-name=LoanBrokerBanksTable \\\n    --item='{ \"Type\": { \"S\": \"Home\" }, \"BankAddress\": {\"L\": [ { \"S\": \"BankRecipientPremium\" }, { \"S\": \"BankRecipientUniversal\" }, { \"S\": \"BankRecipientPawnshop\" } ] } }'\n```\n\nWe can start the State Machine execution to get quotes from the banks after submitting a loan application. Run the following command:\n\n```sh\nawslocal stepfunctions start-execution \\\n    --name=cli-test-run \\\n    --state-machine-arn=\u003cSTATE_MACHINE_ARN\u003e \\\n    --input=\"{\\\"SSN\\\": \\\"123-45-6789\\\", \\\"Amount\\\": 500000, \\\"Term\\\": 30 }\"\n```\n\nReplace `\u003cSTATE_MACHINE_ARN\u003e` with the `LoanBroker-RecipientList-Stack.LoanBrokerArn` output from the previous step. The result will contain the Execution ARN and the start date:\n\n```sh\n{\n    \"executionArn\": \"arn:aws:states:us-east-1:000000000000:execution:LoanBroker-RecipientList-Stack-LoanBroker641FC9A8-dd79232c:cli-test-run\",\n    \"startDate\": \"2023-04-24T21:08:35.434000+05:30\"\n}\n```\n\nYou can use the Execution ARN to see the output of the State Machine execution:\n\n```sh\nawslocal stepfunctions describe-execution \\\n    --execution-arn=\u003cEXECUTION_ARN\u003e \\\n    --query=\"output\" | jq -r  '. | fromjson'\n```\n\nReplace the `\u003cEXECUTION_ARN\u003e` with the `executionArn` output from the previous step. The result will contain the output of the State Machine execution:\n\n```json\n{\n  \"SSN\": \"123-45-6789\",\n  \"Amount\": 500000,\n  \"Term\": 30,\n  \"Credit\": {\n    \"Score\": 861,\n    \"History\": 15\n  },\n  \"Banks\": {\n    \"BankAddress\": [\n      \"BankRecipientPremium\",\n      \"BankRecipientUniversal\",\n      \"BankRecipientPawnshop\"\n    ]\n  },\n  \"Quotes\": [\n    {\n      \"Quote\": {\n        \"rate\": 3.881919225968371,\n        \"bankId\": \"Premium\"\n      }\n    },\n    {\n      \"Quote\": {\n        \"rate\": 5.032719931679686,\n        \"bankId\": \"Universal\"\n      }\n    },\n    {\n      \"Quote\": {\n        \"rate\": 6.019381689166033,\n        \"bankId\": \"PawnShop\"\n      }\n    }\n  ]\n}\n```\n\n## GitHub Action\n\nThis application sample hosts an example GitHub Action workflow that starts up LocalStack, builds the Lambda functions, and deploys the infrastructure on the runner. You can find the workflow in the `.github/workflows/main.yml` file. To run the workflow, you can fork this repository and push a commit to the `main` branch.\n\nUsers can adapt this example workflow to run in their own CI environment. LocalStack supports various CI environments, including GitHub Actions, CircleCI, Jenkins, Travis CI, and more. You can find more information about the CI integration in the [LocalStack documentation](https://docs.localstack.cloud/user-guide/ci/).\n\n## Contributing\n\nWe appreciate your interest in contributing to our project and are always looking for new ways to improve the developer experience. We welcome feedback, bug reports, and even feature ideas from the community.\nPlease refer to the [contributing file](CONTRIBUTING.md) for more details on how to get started. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-loan-broker-stepfunctions-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalstack-samples%2Fsample-loan-broker-stepfunctions-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-loan-broker-stepfunctions-lambda/lists"}