AWS Public Sector Blog

How to build smart cities with FIWARE Orion Context Broker and Cygnus on AWS

Efforts to realize smart cities have been implemented around the world. The city of Santander in Spain embedded more than 12,000 sensors throughout the city to utilize data to reduce environmental issues such as chronic traffic congestion and air pollution. The city of Lisbon in Portugal introduced an intelligent city infrastructure platform to integrate more than 30 systems, including those for transportation and energy, to help improve the quality of services, public safety, mobility, and operational effectiveness for citizens and visitors by collecting and analyzing data.

These cities both use FIWARE, an open source framework supporting the development of smart solutions, like smart cities. FIWARE leverages sensing data from Internet of Things (IoT) devices, then collects, stores, and analyzes data with an API call. One FIWARE component, Orion Context Broker, gathers context information from diverse sources such as mobile apps, IoT devices, and social networking services, and manages the lifecycle of this context information, from registrations, updates, queries, and subscriptions. Context information on Orion Context Broker consists of entities (like a car), and their attributes (like the speed or location of the car). With Orion Context Broker, you can subscribe to dynamic context information, so when some condition occurs and the context elements change, you receive a notification. In Japan, cities like Takamatsu and Kakogawa leverage Orion for disaster prevention and public safety. Recently, MODE, Inc. announced that it completed the validation of its data integration test with Orion.

Orion Context Broker stores the last state of data into a database, so you need to deploy an additional FIWARE component like Cygnus, which is a connector in charge of persisting Orion context data and historical data in third-party databases. This is in case you would like to see a historical view of the data for analysis.

Orion is increasingly being used to realize smart cities, but using these components in conjunction with Amazon Web Services (AWS) allows you to leverage your captured data and get the benefits of the cloud for security, high availability to support a large amount of IoT devices, durability, and enable further data pipelines and integration. These components can be run using container technologies for the Orion Context Broker and Cygnus that can be easily deployed in AWS using services like AWS Fargate or Amazon Elastic Kubernetes Service (Amazon EKS).

In this blog post, we will show you how to deploy the Orion Context Broker, Cygnus, and support databases for these services on AWS. We have created a sample with AWS Cloud Development Kit (AWS CDK) and released it on this GitHub repository.

Architecture overview

The Orion Context Broker and Cygnus run as containers on AWS Fargate using Amazon Elastic Container Service (Amazon ECS). The last state of data is stored into Amazon DocumentDB, through which Orion Context Broker connects. Historical data is stored in Amazon Aurora Serverless v1 using Cygnus. Using these databases provides high scalability, performance, and availability without worrying about management tasks. Figure 1 shows this architecture. Networking resources (such as Amazon Virtual Private Cloud (Amazon VPC), subnets, security groups, AWS WAF and NAT gateway), containers and databases are deployed with AWS CDK.

Figure 1. Diagram of an Orion Context Broker and Cygnus architecture on AWS.

Figure 1. Diagram of an Orion Context Broker and Cygnus architecture on AWS.

Prerequisites

  • Clone the Git repository. Source codes are uploaded on this Git repository, so clone it to your local environment.
  • Install Node.js version >= 16.1

Security considerations

In this demo, the Orion context broker endpoint is only protected by AWS WAF, that is configured in the deployment setting. We strongly encourage you to configure one or more access CIDR that restrict your testing environment and consider options to protect the Orion endpoint following FIWARE recommendations and eco-system.

Additionally, you can also provide your own certificate to the Load Balancer to enable HTTPS communication if required. Please check the AWS documentation here and AWS CDK here

Deployment

  1. Check the settings.ts file to configure your deployment. You can optionally deploy both Orion and Cygnus or only Orion. Additionally, you can configure your AWS region to deploy allowed IPs that can reach Orion endpoint and the configuration for the services like memory, CPU, and initial instance count. For high availability, you should set the value of desiredCount greater than 2.
    1. Security consideration: T
  2. To deploy the AWS CDK project, run the following script command: ./deployer.sh <AWS_PROFILE>

Operation check

After AWS CDK has completed the deployment, you will see a set of Outputs where the FIWARE Orion service URL is listed. Use this URL to access Orion’s API for the following examples:

  1. GET –Orion version

$ curl http://<ORION_FIWARE_ENDPOINT>:1026/version
# Sample output
{
  "orion": {
    "version": "3.1.0-next",
    "uptime": "1 d, 1 h, 19 m, 33 s",
    "git_hash": "7bd1e43514539bd65caeb30d4e3319202e0f115b",
    "compile_time": "Mon Jul 26 08:19:44 UTC 2021",
    "compiled_by": "root",
    "compiled_in": "dae1c5e3a7d9",
    "release_date": "Mon Jul 26 08:19:44 UTC 2021",
    "machine": "x86_64",
    "doc": "https://fiware-orion.rtfd.io/",
    "libversions": {
      "boost": "1_66",
      "libcurl": "libcurl/7.61.1 OpenSSL/1.1.1g zlib/1.2.11 nghttp2/1.33.0",
      "libmicrohttpd": "0.9.70",
      "openssl": "1.1",
      "rapidjson": "1.1.0",
      "mongoc": "1.17.4",
      "bson": "1.17.4"
    }
  }
}

  1. Post – Create an entity

$ curl -sS http://<ORION_FIWARE_ENDPOINT>:1026/v2/entities \ -H 'Content-Type: application/json' \ -H 'fiware-service: demo' \ -H 'fiware-servicepath: /' \ -d @- <<EOF { "id": "living", "type": "Room", "temperature": {"value": 23, "type": "Float"} } EOF

  1. Get – Query the previously created entity

$ curl -sS http://<ORION_FIWARE_ENDPOINT>:1026/v2/entities/living?type=Room \ -H 'fiware-service: demo' \ -H 'fiware-servicepath: /' \ -H 'Accept: application/json'

  1. Put – Update an attribute of the entity, in this case the room temperature to 35

$ curl -sS http://<ORION_FIWARE_ENDPOINT>:1026/v2/entities/living/attrs/temperature/value \ -H 'Content-Type: text/plain' \ -H 'fiware-service: demo' \ -H 'fiware-servicepath: /' \ -X PUT \ -d 35

  1. History – Of future updates

To store the historical data of future updates, you can use Orion’s subscription feature. Run the following request, note the notification attribute that points to Cygnus endpoint http://cygnus.fiware:5055. This endpoint is fixed and created when you deployed the solution using AWS Cloud Map for service discovery. For more information visit the AWS documentation.

curl -v -sS http://<ORION_FIWARE_ENDPOINT>:1026/v2/subscriptions \ -H 'Content-Type: application/json' \ -H 'fiware-service: demo' \ -H 'fiware-servicepath: /' \ -d @- <<EOF { "description": "A subscription to notify info about living", "subject": { "entities": [ { "id": "living", "type": "Room" } ], "condition": { "attrs": [ "temperature" ] } }, "notification": { "http": { "url": "http://cygnus.fiware:5055/notify" }, "attrs": [ "temperature" ], "attrsFormat": "legacy" }, "throttling": 5 } EOF

After this point, all updates/modifications to this entity will be stored by Cygnus using the Amazon Aurora PostgreSQL database. By default, this database can be queried using the data API for Aurora Serverless V1. One option is to use the AWS Management Console, then select RDS and select the Query Editor using the database credentials (Use postgres as database name). For programmatic access, please read the documentation here.

For this demo, the user can be configured in the settings.ts and the password is auto-generated and stored in AWS Secrets Manager where you can retrieve it.

  1. Query – historical data:

select * FROM demo.living_room;
recvtimets | recvtime | fiwareservicepath | entityid | entitytype | attrname | attrtype | attrvalue | attrmd
---------------+-------------------------+-------------------+----------+------------+-------------+----------+-----------+--------
1629351404138 | 2021-08-19 05:36:44.138 | / | living | Room | temperature | Float | 22 | []
1629351409412 | 2021-08-19 05:36:49.412 | / | living | Room | temperature | Float | 17 | []
1629351413194 | 2021-08-19 05:36:53.194 | / | living | Room | temperature | Float | 28 | []

  1. Logs– Application logs for Orion and Cygnus are stored in Amazon CloudWatch Logs (log group named Fiware).

You can view them as needed. You can change the log level detail by modifying the environmental variables for each service in the taskImageOptions constructs for the services respectively.

Conclusion

This post shows how to deploy and test FIWARE Orion Context Broker and Cygnus quickly and easily with AWS CDK. We hope this can help to get you started on how to deploy this and other FIWARE components in AWS to reduce manual steps and focus your time on business logic. As next steps, you can learn more about AWS CDK in the CDK Workshop or discover other ways to easily deploy container applications on AWS with AWS Copilot.

Learn more about AWS and smart cities in the City Transformation hub. Read more stories about how AWS is helping state governments create innovative solutions and smart cities.

More AWS related and smart cities resources:


Subscribe to the AWS Public Sector Blog newsletter to get the latest in AWS tools, solutions, and innovations from the public sector delivered to your inbox, or contact us.

The AWS Public Sector Blog needs your help. Please take a few minutes to share insights regarding your experience with the AWS Public Sector Blog in this survey, and we’ll use feedback from the survey to create more content aligned with the preferences of our readers.

Masahiro Imai

Masahiro Imai

Masahiro Imai is a senior solutions architect in Japan’s public sector for Amazon Web Services (AWS). His area of expertise is machine learning. He helps AWS customers use AWS services for their smart city projects and hopes to apply machine learning to many smart services in the public sector in the future. On weekends, he loves riding motorbikes.

Hidenori Koizumi

Hidenori Koizumi

Hidenori Koizumi is a prototyping solutions architect in Japan’s public sector for Amazon Web Services (AWS). He is an expert in developing solutions in the research field based on his scientific background (biology, chemistry, and more). He has recently been developing applications with AWS Amplify and AWS CDK. He likes traveling and photography.

Jorge Lanzarotti

Jorge Lanzarotti

Jorge Lanzarotti is a prototyping solutions architect in Japan’s public sector for Amazon Web Services (AWS). He loves to use his computer science skills to build scalable and resilient architectures that are easy to deploy and maintain. He has years of experience working and creating platforms in the healthcare and BI markets. Living in Japan since 2016, he enjoys snowboarding and the Japanese culture.