Task App - Deploy to AWS

The following instructions show the deployment to an AWS account with the default setup (Default VPC).

Setup AWS

IAM User Setup

  1. Log in to AWS account
  2. Go to Users
    • Open Identity and Access Management (IAM)
    • Open the sub menu Users
  3. Create User
    • Click Create user:
    • Type a name of your choice.
    • No need for AWS Management Console access
    • Click Next
  4. Add AdministratorAccess Permissions
    • Select Attach policies directly
    • Check the Policy AdministratorAccess
    • Click Next
  5. Review
    • Click Create user
  6. Create access key
    • Click on the new created user
    • Click Create access key
    • Select Command Line Interface (CLI)
    • Select the Confirmation checkbox
    • Click Next
  7. Save the Access Key and Secret access key securely on your device
    • Click Show
    • Click copy Access Key and save it securely on your device
    • Click copy Secret access key and save it securely on your device

Local Setup

  1. Configure your CLI with the Access Key and Secret access key:
    1export AWS_ACCESS_KEY_ID="<PASTE_ACCESS_KEY>"
    2export AWS_SECRET_ACCESS_KEY="<PASTE_SECRET_ACCESS_KEY>"
    3export AWS_DEFAULT_REGION="<PASTE_DEFAULT_REGION (e.g., eu-central-1)>"
  2. Install AWS Serverless Application Model (SAM)

Deployment

Deploy Bounded Context

  1. Navigate to the root folder of your code project. It will contain the following items.

    1.env
    2.gitignore
    3Task
    4package.json
    5template.yaml

  2. Run the deployment command:

    1npm run deploy

  3. Save the EventBusArn, EventBusName, and PostgresEndpoint printed in the CloudFormation output.

    1Key EventBusName
    2Description -
    3Value Taskbricks-EventBus
    4
    5
    6Key PostgresEndpoint
    7Description -
    8Value taskbricks.XXXXXXXXXXXX.eu-central-1.rds.amazonaws.com
    9
    10
    11Key EventBusArn
    12Description -
    13Value arn:aws:events:eu-central-1:XXXXXXXXXXXX:event-bus/Taskbricks-EventBus

Components

The Bounded Context Infrastructure Stack consists of two components:

  • EventBridge, the Event Bus for the communication within and between aggregates of the bounded context
  • RDS Postgres, Database for the persistence of aggregates of the bounded context

Deploy Task Aggregate

  1. Navigate to the Task subfolder. It should look like this:

    1.env
    2.env-test
    3openapi.yaml
    4package.json
    5src
    6template.yaml
    7tests
    8tsconfig.build.json
    9tsconfig.json

  2. Set these values in the .env file:

    1POSTGRES_URL="postgres://username:password@<POSTGRES_ENDPOINT>/postgres"
    2EVENT_BUS_ARN="<EVENT_BUS_ARN>"
    3EVENT_BUS_NAME="<EVENT_BUS_NAME>"
    4JWT_SECRET="<JWT_SECRET>"

    • Replace <POSTGRES_ENDPOINT> with the PostgresEndpoint output of the Bounded Context Deployment
    • Replace <EVENT_BUS_ARN> with the EventBusArn output of the Bounded Context Deployment
    • Replace <EVENT_BUS_NAME> with the EventBusName output of the Bounded Context Deployment
    • Replace <JWT_SECRET> with the output of JWT Secret Generator or similar.
  3. Run the build command:

    1npm run build

  4. Run the deployment command:

    1npm run deploy

  5. Save the ApiGatewayEndpoint printed in the CloudFormation output.

    1Key ApiGatewayEndpoint
    2Description -
    3Value https://XXXXXXXXXX.execute-api.eu-central-1.amazonaws.com/Prod

Components

An Aggregate Infrastructure Stack consists of the following components:

  • API Gateway
    • POST /add-task endpoint
    • POST /complete-task endpoint
    • GET /assignee-task-overview endpoint
  • 7 Lambda Functions
    • Add Task Command
    • Complete Task Command
    • Task Overview Query
    • Task Overview Projection
    • Task Overview Projection Recreater
    • Task Aggregate Event Publisher
    • Task Aggregate Authorizer
  • 2 Lambda Layers
    • Shared Layer
    • Node Modules Layer
  • 2 SQS Queues
    • Task Overview Projection Queue
    • Task Aggregate Event Publisher Queue
  • 2 SQS Queues Policies
    • Task Overview Projection Queue Policy
    • Task Aggregate Event Publisher Queue Policy
  • 1 EventBridge Rule
    • Task Overview Projection Rule

Try the application

  1. Paste the ApiGatewayEndpoint from the previous step into the openapi.yaml under server -> url
    1servers:
    2 - url: https://domainname.com
    • Replace https://domainname.com with https://XXXXXXXXXX.execute-api.eu-central-1.amazonaws.com/Prod
  2. Open Postman
  3. Click Import
  4. Click 'select files' link and select the openapi.yaml file
  5. Navigate to Collections
  6. Start making requests!

© 2024 Codebricks | All rights reserved.