massi-ang / greengrass-cdk

Apache License 2.0
4 stars 0 forks source link

Creating a Greengrass Group with a device generates incorrect Cloudformation output. #1

Closed kennycoder closed 4 years ago

kennycoder commented 4 years ago

Using your example as base code I modified it slightly to add a thing into the group:

let a_s = new iot.CfnThing(this, 'a_sensor', {
          thingName: 'MyThingSensor',
        })
       let a_group = new gg.Group(this, 'a_group', {
            core: new gg.Core(this, 'a_core', {
                thing: a_t,
                syncShadow: true,
                certificateArn: props.certificateArnCore
            }),
            devices: [new gg.Device(this, 'a_sensor_device', {
              thing: a_s,
              syncShadow: false,
              certificateArn: props.certificateArnSensor
            })],
            functions: [gg_lambda],
            subscriptions: subscriptions,
            loggers: [localLogger],
            resources: [tmp_folder]
        })

Unfortunately this fails with the following error during deployment:

AwsBlueprintIotStack failed: ValidationError: Template error: resource asensor does not support attribute type arn in Fn::GetAtt
Template error: resource asensor does not support attribute type arn in Fn::GetAtt

After looking into CF template output I noticed the following:

"agroupagroupdevicesA720B9C5": {
      "Type": "AWS::Greengrass::DeviceDefinition",
      "Properties": {
        "Name": "a_group",
        "InitialVersion": {
          "Devices": [
            {
              "CertificateArn": "arn:aws:iot:eu-central-1:980409644593:cert/263d1b96d60b71109613cedd6c3b701e96a99d706b9f622db2161d099ab21e62",
              "Id": "a_sensor_device",
              "SyncShadow": false,
              "ThingArn": {
                "Fn::GetAtt": [
                  "asensor",
                  "arn"
                ]
              }
            }
          ]
        }
      },

If you look at the ThingArn it tries to use GetAtt which indeed does not exist. Analyzing the same block of code for the thing that is associated to GG Core, it generated the ARN diffferenly:

...
"ThingArn": {
"Fn::Join": [
  "",
  [
    "arn:",
    {
      "Ref": "AWS::Partition"
    },
    ":iot:",
    {
      "Ref": "AWS::Region"
    },
    ":",
    {
      "Ref": "AWS::AccountId"
    },
    ":thing/MyThingCore"
  ]
]
}
...

And this works. My question is, is this CDK related or related to your CDK constructs? Regards, Nikolai

massi-ang commented 4 years ago

Can you get the latest commit and test it?

kennycoder commented 4 years ago

Works as expected now. Appreciated! Closing.