Skip to content
hello-nrfcloudPublic

About

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

Topics

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2,990 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Node & NPM

This project requires Node.js >=26.13.1 <27 and npm >=12.2.3 <13 (enforced via check-node-version on npm install and npm ci). The check is skipped during npm publish and npm pack, so it does not interfere with semantic-release, which runs its own dependency installation as part of the release process.

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

TypeScript 6 and 7

This repo runs TypeScript 6 and 7 side by side, so that eslint works.

Run once

Configure the nRF Cloud project, the MQTT bridge, and create the device used for the health checks.

The backend uses the project-scoped nRF Cloud API (/v1/organizations/<organization>/projects/<project>/...), which authenticates using an Organization Auth Token (see the transition guide). The slugs are shown in Project Settings > General.

The Organization Auth Token needs these permissions (see the REST API transition guide and the API reference):

  • device:read: the backend reads the device state (shadow) and the location history.
  • device:write: the backend updates the device state (configuration changes sent from the web application).

The documentation does not list a permission for these endpoints, which only the CLI uses with the token:

  • creating devices in bulk (import-device, import-devices, create-health-check-device) and reading the bulk operation status (get-nrfcloud-bulkops-status),
  • listing and showing devices (list-devices, show-device, show-nrfcloud-account).

The legacy API key is still needed for FOTA, which has not been migrated yet (see #1914), and for the MQTT bridge: initialize-nrfcloud-account creates the account device the bridge uses to connect to nRF Cloud.

./cli.sh configure-account organizationAuthToken <Organization Auth Token> # e.g. oat_...
./cli.sh configure-account organizationSlug <organization slug>
./cli.sh configure-account projectSlug <project slug>
./cli.sh configure-account apiKey <API key> # legacy API key, used for FOTA and the MQTT bridge
./cli.sh initialize-nrfcloud-account
./cli.sh create-health-check-device

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.

Memfault integration

The backend fetches device metrics from Memfault. This is a second Memfault project, separate from the nRF Cloud project configured above, because the hello.nrfcloud.com firmware reports its metrics into that project. The nRF Cloud project is used for the location services and the device API.

For this you need to configure the settings for your Memfault project:

./cli.sh configure-memfault organizationAuthToken <organizationAuthToken> # e.g. oat_18By8mEdkEj666666666666kIt9HwsMZ
./cli.sh configure-memfault organizationSlug <organizationSlug> # e.g. hello-nrfcloud123456
./cli.sh configure-memfault projectSlug <projectSlug> # e.g. prod

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

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.

gh secret set AWS_ROLE --env production --body `arn:aws:iam::<account ID>:role/<stack name>-cd`
gh variable set AWS_REGION --env production --body <region>
gh variable set STACK_NAME --env production --body <stack name>

Custom API domain

Optionally, a custom API domain can be configured.

For this, create a certificate for the domain name in the Certificate Manager of the production account in the region of the deployment.

Create a role in the account that manages the domain name, to allow the the production account to update the CNAME for the API domain with these permissions (make sure to replace <Hosted Zone ID>, <api domain name>):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "route53:ChangeResourceRecordSets",
      "Resource": "arn:aws:route53:::hostedzone/<Hosted Zone ID>",
      "Condition": {
        "ForAllValues:StringEquals": {
          "route53:ChangeResourceRecordSetsNormalizedRecordNames": [
            "<api domain name>"
          ],
          "route53:ChangeResourceRecordSetsRecordTypes": ["CNAME"],
          "route53:ChangeResourceRecordSetsActions": ["UPSERT"]
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": "route53:ListHostedZonesByName",
      "Resource": "*"
    }
  ]
}

Then, for continuous deployment:

  • create the variable API_DOMAIN_NAME with the name of the api domain, e.g. api.hello.nordicsemi.cloud
  • create the secret API_DOMAIN_ROUTE_53_ROLE_ARN with the role ARN of the role that allows the production account to update the CNAME for the API domain.
gh variable set API_DOMAIN_NAME --env production --body api.sim-details.nordicsemi.cloud
gh secret set API_DOMAIN_ROUTE_53_ROLE_ARN --env production --body arn:aws:iam::<account ID>:role/<role name>

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.

About

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

Topics

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages