(golang) awscdk/v2/awsiot: CfnTopicRule_DynamoDBv2ActionProperty empty generated cfn
See original GitHub issueWhat 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:
- Created 2 years ago
- Comments:13 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.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!