Skip to content

localstack-samples/sample-cdk-event-bridge-microservices

CDK deployment of Sample Microservice System of Lambda Functions connected via multiple EventBridge Buses

LocalStack sample CDK app deploying cross-region and cross-account EventBridge buses and Lambda functions connected to them.

Key Value
Environment
Services EventBridge, Lambda, SimpleQueueService
Integrations CDK
Categories EventDriven
Level Intermediate
GitHub Repository link

architecture diagram showing the pipeline including Lambda producers, cross-region / cross-account EventBridge buses and Sqs consumers

Prerequisites

Required Software

if you are on Mac:
1. install python@3.11
    
    ```bash
    brew install pyenv
    pyenv install 3.11.0
    ```

2. install nvm and node >= 16

    ```bash
    brew install nvm
    nvm install 20
    nvm use 20
    ```
3. install docker

    ```bash
    brew install docker
    ```

4. install aws cli, cdk

    ```bash
    brew install awscli
    npm install -g aws-cdk
    ```

5. install localstack-cli and cdklocal
    
    ```bash
    brew install localstack/tap/localstack-cli
    npm install -g aws-cdk-local
    ```

Setup development environment

Clone the repository and navigate to the project directory.

git@github.com:localstack-samples/sample-cdk-event-bridge-microservices.git
cd sample-cdk-event-bridge-microservices

Copy .env.example to .env and set the environment variables based on your target environment. Make sure to setup both accounts you want to deploy to accordingly.

Create a virtualenv using python@3.11 and install all the development dependencies there:

pyenv local 3.11.0
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Deployment

  • Configure the AWS CLI for both accounts
  • Set the environment variables in the .env file based on .env.example (if you want to deploy against AWS make sure to set the correct profile names for your aws cli configuration ACCOUNT_PROFILE_NAME_SECONDARY=<name> it must be the same as in your .aws/config file)

Deploy the CDK stack

Against AWS

  • bootstrapping is required for the first deployment of both accounts and regions
cdk bootstrap aws://<account-id>/<region> --profile <profile-name>
  • use the Makefile command deploy-aws or run the following commands manually
cdk synth
cdk deploy EventsStackPrimary 
cdk deploy EventsStackSecondaryRegion
cdk deploy EventsStackSecondaryAccount

Against LocalStack

  • use the Makefile command deploy-localstack or run the following commands manually
  • You need to bootstrap for the desired region and account each time you start LocalStack
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
make start
make ready
cdklocal synth
cdklocal bootstrap aws://000000000000/us-east-1
cdklocal bootstrap aws://000000000000/eu-central-1
cdklocal bootstrap aws://000000000001/us-east-1
cdklocal deploy EventsStackPrimary --require-approval never
cdklocal deploy EventsStackSecondaryRegion --require-approval never
cdklocal deploy EventsStackSecondaryAccount --require-approval never

Testing

Run the tests either against AWS or LocalStack

make test

This will run a pytest defined in tests/test_event_bridge_microservice.py, there are two tests, one for cross-account and one for cross-region EventBridge buses, make sure that the correct stacks are deployed to the correct regions and accounts. The tests will trigger the Lambda functions and assert that the data is being sent to the correct SQS queues.

Contributing

We 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. Please refer to the contributing file for more details on how to get started.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors