question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(golang) awscdk/v2/awsiot: CfnTopicRule_DynamoDBv2ActionProperty empty generated cfn

See original GitHub issue

What is the problem?

When I construct a TopicRule using CfnTopicRule_DynamoDBv2ActionProperty, then the generated CloudFormation is missing the actual action details.

Reproduction Steps

	ddbV2Action := &awsiot.CfnTopicRule_ActionProperty{
		DynamoDBv2: &awsiot.CfnTopicRule_DynamoDBv2ActionProperty{
			PutItem: awsiot.CfnTopicRule_PutItemInputProperty{
				TableName: table.TableName(),
			},
			RoleArn: iotRole.RoleArn(),
		},
	}

	ruleprops := &awsiot.CfnTopicRuleProps{
		TopicRulePayload: awsiot.CfnTopicRule_TopicRulePayloadProperty{
			Actions:          &[]*awsiot.CfnTopicRule_ActionProperty{ddbV2Action},
			AwsIotSqlVersion: aws.String("2016-03-23"),
			Sql:              aws.String(sqlStatement),
		},
	}

	awsiot.NewCfnTopicRule(stack, aws.String("ExampleRule"), ruleprops)

What did you expect to happen?

I expected the Output to look like this:

  Type: AWS::IoT::TopicRule
    Properties:
      TopicRulePayload:
        Actions:
          - DynamoDBv2:
              PutItem:
                TableName:
                  Ref: <table name redacted>
              RoleArn:
                Fn::GetAtt:
                  - IoTtoDynamoDBRole47C5C8A5
                  - Arn
        AwsIotSqlVersion: "2016-03-23"
        Sql: <sql redacted>

What actually happened?

I only see this:

  Type: AWS::IoT::TopicRule
    Properties:
      TopicRulePayload:
        Actions:
          - DynamoDBv2: {}
        AwsIotSqlVersion: "2016-03-23"
        RuleDisabled: false
        Sql: <sql redacted>

CDK CLI Version

2.0.0 (build 4b6ce31)

Framework Version

No response

Node.js Version

v17.2.0.

OS

macOS Monteray

Language

Go

Language Version

Go 1.17.3

Other information

A workaround:

ddbV2Action := &awsiot.CfnTopicRule_ActionProperty{
		DynamoDBv2: &awsiot.CfnTopicRule_DynamoDBv2ActionProperty{
			PutItem: awsiot.CfnTopicRule_PutItemInputProperty{
				TableName: table.TableName(),
			},
			RoleArn: iotRole.RoleArn(),
		},
	}

	ruleprops := &awsiot.CfnTopicRuleProps{
		TopicRulePayload: awsiot.CfnTopicRule_TopicRulePayloadProperty{
			Actions:          &[]*awsiot.CfnTopicRule_ActionProperty{ddbV2Action},
			AwsIotSqlVersion: aws.String("2016-03-23"),
			Sql:              aws.String(SqlString),
		},
	}

	bytes, err := json.MarshalIndent(ruleprops, "", "    ")
	if err != nil {
		panic(err)
	}

	correctProps := &awsiot.CfnTopicRuleProps{}
	err = json.Unmarshal(bytes, correctProps)
	if err != nil {
		panic(err)
	}

	awsiot.NewCfnTopicRule(stack, aws.String("EampleRule"), correctProps)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
karl-daucommented, Dec 14, 2021

@skinny85 Thanks! that was it!

I got confused with optionals being pointer types and building up those structs with values and not pointers. The JSON marshal/unmarshal trick works because the reflection code dereferences those pointers. I guess everything taking interface{} also did not help.

0reactions
skinny85commented, Dec 14, 2021

BTW, we now have Layer 2 IoT constructs: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-iot-readme.html, you might want to check them out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

cfn - Go Packages
Package cfn provides the Template type that models a CloudFormation ... Package spec contains generated models for CloudFormation and IAM.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found