Skip to content

(@aws-cdk/aws-iot): CfnLocationAction asks for Date type despite spec wanting Timestamp type #22732

@dreamorosi

Description

@dreamorosi

Describe the bug

The iot.CfnTopicRule construct now supports an action called LocationAction (link to CloudFormation docs).

The LocationAction entity has a property called Timestamp which according to the CloudFormation docs is supposed to be of type AWS::IoT::TopicRule Timestamp and have shape:

{
  "Unit": String,
  "Value": String
}

At present, in version 1.179.0 the property has incorrect type of Date, which causes the synth step to fail.

Expected Behavior

The resource should have the correct type and allow to deploy correctly.

Current Behavior

Error:

cdk-stack.ts(114,17): error TS2322: Type '{ value: string; unit: string; }' is not assignable to type 'Date | IResolvable'.
  Object literal may only specify known properties, but 'value' does not exist in type 'Date | IResolvable'

Screenshot 2022-11-01 at 15 26 20

Reproduction Steps

import * as cdk from "@aws-cdk/core";
import * as iot from "@aws-cdk/aws-iot";
import * as iam from "@aws-cdk/aws-iam";

export class cdkStack extends cdk.Stack {
  constructor(
    scope: cdk.Construct,
    id: string,
    props?: cdk.StackProps,
  ) {
    super(scope, id, props);

    const role = new iam.Role(this, "iot-tracker-role", {
      assumedBy: new iam.ServicePrincipal("iot.amazonaws.com"),
      description: "IAM Role that allows IoT Core to update a Tracker",
      inlinePolicies: {
        allowTracker: new iam.PolicyDocument({
          statements: [
            new iam.PolicyStatement({
              resources: [
                `arn:aws:geo:${cdk.Stack.of(this).region}:${
                  cdk.Stack.of(this).account
                }:tracker/tracker_location_workshop`,
              ],
              actions: ["geo:BatchUpdateDevicePosition"],
            }),
          ],
        }),
      },
    });

    // Create an IoT Topic Rule that will send the location updates to Location Service
    const topicRule = new iot.CfnTopicRule(this, "TopicRule", {
      ruleName: "assetTrackingRule",
      topicRulePayload: {
        sql: `SELECT * FROM 'iot/trackedAssets'`,
        awsIotSqlVersion: "2016-03-23",
        actions: [
          {
            location: {
              deviceId: "${deviceID}",
              latitude: "${longitude}",
              longitude: "${latitude}",
              roleArn: role.roleArn,
              timestamp: {
                value: "${timestamp()}",
                unit: "MILLISECONDS",
              },
              trackerName: "tracker_location_workshop",
            },
          }
        ],
      },
    });
  }
}

Possible Solution

Change the type to the correct one.

Additional Information/Context

Adding this manual override to the resource allows to deploy correctly, proving that the resource is mistyped in CDK:

topicRule.addOverride("Properties.TopicRulePayload.Actions.0", {
      Location: {
        DeviceId: "${deviceID}",
        Latitude: "${longitude}",
        Longitude: "${latitude}",
        RoleArn: role.roleArn,
        Timestamp: {
          Value: "${timestamp()}",
          Unit: "MILLISECONDS",
        },
        TrackerName: "tracker_location_workshop-ok",
      },
    });

CDK CLI Version

2.41.0

Framework Version

No response

Node.js Version

16.15.0

OS

Linux / macOS

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-iotRelated to AWS IoTbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions