Skip to main content

Deploying to AWS

Once you're happy with your code, it's time to deploy the application into your AWS account. This guide will walk you through setting up AWS resources and deploying your application.

note

If you're using the starter plan, a custom domain is not required. To use a custom domain, enable the **ustom plan.

AWS Setup

IAM User Setup

  1. Open IAM in the AWS Console.
  2. Create a new IAM User:
    • No need for AWS Management Console access.
  3. Attach the AdministratorAccess permission to the user.
  4. Generate an Access Key for the IAM User (select CLI use case).
  5. Save the Access Keys securely on your device.

Local Setup

  1. Configure your CLI with the IAM Access Keys:
    export AWS_ACCESS_KEY_ID=\\<PASTE_ACCESS_KEY\\>
    export AWS_SECRET_ACCESS_KEY=\\<PASTE_SECRET_ACCESS_KEY\\>
    export AWS_DEFAULT_REGION=\\<PASTE_DEFAULT_REGION (e.g., eu-central-1)\\>
  2. Install AWS SAM by following this guide.

Deployment

Deploy Bounded Context

  1. Navigate to the root folder of your application.

  2. Set these values in the .env file:

    POSTGRES_USERNAME=\\<CHOOSE_DB_USER_NAME\\>
    POSTGRES_PASSWORD=\\<CHOOSE_PASSWORD\\>
    warning

    Values should not be wrapped in quotes. Be careful with special characters. For more details, see this Stack Overflow thread.

  3. Run the deployment command:

    npm run deploy
  4. Save the EventBusArn, EventBusName, and PostgresEndpoint printed in the response.

Deploy Aggregate

  1. Generate a JWT Secret on JWT Secret Homepage.

  2. Navigate to the Aggregate subfolder.

  3. Set these values in the .env file from the output from the previous CLI command response:

    POSTGRES_URL=postgres://\\<POSTGRES_USERNAME\\>:\\<POSTGRES_PASSWORD\\>@\\<POSTGRES_ENDPOINT\\>/postgres
    EVENT_BUS_ARN=\\<EVENT_BUS_ARN\\>
    EVENT_BUS_NAME=\\<EVENT_BUS_NAME\\>
    JWT_SECRET=\\<JWT_SECRET\\>
  4. Run the build command:

    npm run build
  5. Run the deployment command:

    npm run deploy
  6. Save the ApiGatewayEndpoint printed in the response.

Testing

  1. Paste the ApiGatewayEndpoint from the previous step into the openapi.yaml under server -> url.
  2. Open Postman.
  3. Navigate to Collections.
  4. Import the openapi.yaml file.
  5. Start making requests!