AWS S3 (HTTP)

In this example, we configure an HTTP connection that publishes twin events to AWS S3 (Simple Storage Service).

Prerequisites

To follow this example you will need:

  • A Bosch IoT Things service subscription
  • An AWS S3 bucket
  • An AWS IAM user with access to S3

Create the connection

  • Click Go to Dashboard in the row of your Things instance, which will manage the connection.
  • On the Things dashboard open the tab Connections/Integrations.
  • Click Create your first connection, or Add in case you have one already.
    • Select HTTP from the categories.
    • Give the connection a name. Setting a name is required.
    • Click the Continue button.
create-http-connection

Configure credentials

  • Scroll to the Coordinates section.
  • Choose hmac as the credential type.
  • Choose aws4-hmac-sha256 as the algorithm.
  • Enter the AWS region of your S3 bucket, e.g. eu-central-1.
  • Enter s3 as the AWS service name.
  • Enter the access key of the S3 user.
  • Enter the secret key of the S3 user.
  • Uncheck “Double encode and normalize path segments”.
  • Choose INCLUDED for Payload hash as header-

aws-s3-coordinates-1

Configure the hostname

  • Scroll to the Connection coordinates section.
  • Enter the hostname of your S3 bucket: <bucket-name>.s3.<aws-region>.amazonaws.com

aws-s3-coordinates-2

Add a target

  • Scroll to the Targets section.
  • Click the Add target button.
  • Choose PUT as the HTTP verb.
  • Enter / as the HTTP path.
    Payload mapping will compute the HTTP path for each twin event so that events are stored as distinct objects
  • Add an authorization subject, e.g. integration:<solution-id>:s3.
  • Check Thing twin events under Topics to publish on address.
  • Click Save new target.

aws-s3-target

Configure payload mapping

  • Scroll to the Payload mapping section.
  • Check Enable custom JavaScript-based payload mapping.
  • Change the outgoing payload mapping to compute a unique S3 object name for each event, and set it as the path of the outgoing HTTP request via the special header http.path.
    A thing-modified event for the thing com.acme:coffee-brewer of revision 42 would create the S3 object com.acme:coffee-brewer:things:twin:events:modified:42
function mapFromDittoProtocolMsgWrapper(msg) {
  let topic = msg['topic'].split('/').join(':');
  let headers = {
      'http.path': topic + ':' + msg['revision']
  };
  let textPayload = JSON.stringify(msg);
  let bytePayload = null;
  let contentType = 'application/json';

  return Ditto.buildExternalMsg(headers, textPayload, bytePayload, contentType);
}
  • Click the Create button at the top right to save the connection.

Authorize the connection for twin events

Follow the steps “Create a Hello World thing” and “Add the authorization subject of the connection to the policy” on the Hub-to-Things connection tutorial to authorize the S3 connection to receive twin events.

Remember to use the authorization subject of this connection in the policy, e.g. integration:<solution-id>:s3.

Subsequent twin modifications will create objects in the S3 bucket containing the corresponding events.

Corporate information Data protection notice Legal information Support Free plans