Skip to content

Cloud backend for hello.nrfcloud.com developed using AWS CDK in TypeScript

License

Notifications You must be signed in to change notification settings

hello-nrfcloud/backend

hello.nrfcloud.com backend

GitHub Actions semantic-release Renovate @commitlint/config-conventional code style: prettier ESLint: TypeScript

Cloud backend for hello.nrfcloud.com developed using AWS CDK in TypeScript.

Installation in your AWS account

Setup

Provide your AWS credentials.

Install the dependencies

npm ci

The CoAP simulator is written in Golang, which needs to be present on the local system.

Run once

To setup MQTT bridge, you have to run the below command to generate a certificate used by MQTT broker to connect nRF Cloud under your account. So, you need to prepare nRF Cloud API key.

./cli.sh configure-nrfcloud-account <account> apiKey <API key>
./cli.sh initialize-nrfcloud-account <account>
./cli.sh create-health-check-device <account>

nRF Cloud Location Services Service Key

The single-cell geo-location features uses the nRF Cloud Ground Fix API which requires the service to be enabled in the account's plan. Manage the account at https://nrfcloud.com/#/manage-plan.

Build the docker images

Some of the feature are run from docker containers, ensure they have been built and published before deploying the solutions.

export MQTT_BRIDGE_CONTAINER_TAG=$(./cli.sh build-container mqtt-bridge)

# You can add these outputs to your .env file
echo MQTT_BRIDGE_CONTAINER_TAG=$MQTT_BRIDGE_CONTAINER_TAG

Deploy

npx cdk bootstrap # if this is the first time you use CDK in this account
npx cdk deploy --all

What messages MQTT bridge forwards

According to nRF Cloud documentation, Setting up a message bridge, all messages under <stage>/<team id>/m/# are bridged. Since the messages are forwarded from nRF Cloud, therefore all messages are following the protocol described here.

Note Shadow data will NOT be forwarded to MQTT bridge since they are using topic as $aws/things/${deviceId}/shadow/update

Adding another nRF Cloud team

The backend supports the integration with multiple nRF Cloud accounts.

Follow the steps above to set up the MQTT bridge for another account, then trigger a deployment.

npx cdk deploy --all

List the configured accounts:

./cli.sh list-nrfcloud-accounts

Continuous Deployment using GitHub Actions

After deploying the stack manually once,

  • configure a GitHub Actions environment named production
  • create the secret AWS_ROLE with the value arn:aws:iam::<account ID>:role/<stack name>-cd and a variable (use the cdRoleArn stack output)
  • create the variable AWS_REGION with the value <region> (your region)
  • create the variable STACK_NAME with the value <stack name> (your stack name)

to enable continuous deployment.

Websocket Protocol

Message received from MQTT bridge will be published to websocket connection that associates with the same device id.

Messages will be converted using @hello.nrfcloud.com/proto.