LogoLogo
  • KPN THINGS USER GUIDE
    • Introduction
    • Getting started
      • Registration and setup
      • Device simulator app
      • Connect devices
        • SIM cards
        • Supported devices and KPN Devices
        • SODAQ R412M
        • Smartrak
        • Marvin development board
        • LoPy5
        • Arduino MKR WAN 1300/1310
        • Arduin MKR NB 1500
    • All videos
    • Tutorials
      • Configure a flow
      • Connect a HTTPs destination
      • Create a simple IoT web applicationPage
      • Send instruction to LoRa DevicePage
      • Send your data to Azure SQL
      • Technical overview
        • Management data model
        • Uplink communication
        • Downlink communication
        • Location data
      • Accounts and projects
        • Customer accounts and users
        • Projects
        • Customer management
        • Cost overview and contract
    • Frequently asked
      • Multi Factor Authentication
  • GENERAL FUNCTIONS
    • Quick reference videos
    • APIs
  • THE PORTAL EXPLAINED
    • Things Manager
      • Devices
        • Bulk operations
      • Data
        • Device data graph
      • Connectivity
        • LoRa connectivity configuration
      • Bulk reports
    • Things Creator
    • Support
      • News
      • Release notes
      • Real-time status
      • Service reports
      • Documents
      • Support tickets
      • Invoices
      • Contact info
    • Shop
  • BUILDING BLOCKS
    • Devices
      • Sensors
        • KPN Conditionsensor CO2 II
        • KPN Conditionsensor CO2 III
        • KPN Conditionsensor CO2 III motionPage 1
        • KPN FillTag I
        • KPN FillTag II
        • 1M2M ED1608
        • Elsys ERS
        • Device Simulator (Mobile Phone app)
        • Generic Device (Internet connected)
        • Generic LoRa device (preset connectivity)
        • Generic LoRa device (programmable)
        • Generic M2M device
        • Generic M2M device (with Internet connection)
      • Trackers
        • KPN Global Tracker Autonomous
        • KPN Global Tracker Wired
        • KPN LocationTag I
        • KPN LocationTag II
        • KPN LocationTag II v2
        • KPN LocationTag II v2 Expert Mode
        • KPN LocationTag II v3
        • KPN LocationTag III (with GPS)
        • KPN LocationTag III (without GPS)
        • KPN LocationTag III v2
        • KPN LocationTag III v2 Buffer
        • KPN LocationTag III v3
        • KPN LocationTag III v4
        • KPN LocationTag V
        • KPN LocationTag VI
        • KPN LocationTag WS
        • Streamline LoRa
        • Streamline M2M
        • Viloc
      • Routers
      • Gateways
        • KPN FSK Basestation
      • Device SDK
    • Connectivity
      • Connecting LoRa devices
        • LoRa connectivity configuration
      • Connecting M2M devices
      • Connecting Internet devices
      • Connecting MQTT Devices
    • Data Processing
      • ThingsML and SenML
        • ThingsML
        • SenML
          • Understanding and Interpreting SenML Data
          • Changes in KPN SenML
      • Device Twin
      • Decoders and encoders
        • Common measurements list
        • Decoder migrations
        • DIY Decoder
          • DIY decoder scripts
      • Merger
      • Device data
      • Devices
    • Destinations
      • HTTPS destination
      • MQTT broker
      • Cumulocity IoT Platform
      • Azure Event Hubs
      • Azure IoT Hub
      • Test Endpoint
      • ThingsBoard
      • Datacake
      • AWS Lambda
      • Google Cloud Run functions
  • IOT LINE UP
    • Freemium
      • Test SIM cards
    • Explorer
    • Modular
    • Tailored
    • Terms and Conditions
Powered by GitBook

© 2024 KPN - All rights reserved.

On this page
  • KPN Things: Configure an AWS Lambda destination
  • Naming
  • Connection details
  • AWS: Create an integration
  • KPN Things: Continue with Configure a AWS destination

Was this helpful?

Export as PDF
  1. BUILDING BLOCKS
  2. Destinations

AWS Lambda

PreviousDatacakeNextGoogle Cloud Run functions

Last updated 3 months ago

Was this helpful?

KPN Things: Configure an AWS Lambda destination

Naming

Give your AWS Destination a nice name and optionally a description.

Connection details

First you need to create an AWS account (AWS Free Tier) on, or use an existing AWS account. Then follow the instructions below to create an integration in your AWS account. Keep your KPN Things Destination configuration screen open, as you will need to copy information from and to it later.


AWS: Create an integration

This is an example to integrate directly with an AWS Lambda function.

There are other alternatives, like AWS API gateway combined with an Lambda Authorizer.

Log in to your AWS account and go to Services > Lambda. There, click the Create function button and follow the steps below.

1. Basic information

In the first step, enter the following information.

  • Function name Enter a name that describes the purpose of your function.

  • Runtime Choose the language to use to write your function.

  • Architecture

    Choose the instruction set architecture you want for your function code.

Permissions and Advanced Settings can be left to default.

Click Create Function.

2. Code

Select the Code tab to define your code.

3. Configuration

In the Configuration tab choose the option Function URL.

Then Click Create function URL and choose your Auth type, in this case NONE.

Click Save. This result in Function URL.

KPN Things: Continue with Configure a AWS destination

In this step, you need to copy/paste information from AWS to Things. So pay attention, please.

Go back to the KPN Things Destination configuration screen and fill the remain fields.

  • HTTP endpoint URL Copy the Function URL from AWS into the KPN Things Destination configuration.

def lambda_handler(event, context):
    # This is an example.
    # Make sure you store the sharedSecret in a safe place,
    # e.g. using AWS Secret Manager.
    
    sharedSecret='[Fill in your shared secret]'
    requestBody=event['body']
    thingsMessageToken=event['headers']['things-message-token']
    input = requestBody + sharedSecret;
    
    def calculate_sha256(data):
    # Convert data to bytes if it’s not already
        if isinstance(data, str):
            data = data.encode()
        # Calculate SHA-256 hash
        sha256_hash = hashlib.sha256(data).hexdigest()
        return sha256_hash 
    
    
    if thingsMessageToken == calculate_sha256(input):
    # Define further action
        return {
            'statusCode': 201,
        }
    else:
        return {
            'statusCode': 401,

        }

Finally, go back to the KPN Things Destination configuration screen and press the Add AWS destination button to save the new Destination in KPN Things.

Now, you are finished and good to go!

Shared secret With the shared secret you have the possibility to verify that Things has sent the data and not someone else, because with the shared secret a unique is calculated for each message. Within the Lambda function you can repeat the calculation and check whether the calculated Things-Message-Token is the same as the received Things-Message-Token. Below you can find an example of a calculation and a check in Python.

Things-Message-Token
https://aws.amazon.com/free
Creating a Lambda function
Configuring a Function URL