jsii icon indicating copy to clipboard operation
jsii copied to clipboard

(aws-iotevents): golang: export _bind so that L2 constructs can be written in Go

Open karl-dau opened this issue 2 years ago • 4 comments

Describe the feature

I want to write my own IAction in Go (for SNS publishing), but I cannot seem to satisfy the correct interface.

Looking at the definition:

export interface IAction {
  /**
   * Returns the AWS IoT Events action specification.
   * @internal
   */
  _bind(scope: Construct, options: ActionBindOptions): ActionConfig;
}

_bind is not exported so it is not part of the generated Go IAction.

the aws-iot Actions used to have Bind exported and I could write my own actions before CDK officially supported the DynamoDBv2 action.

Passing in a Go a struct with method:

func (action *IoTEventSNSAction) _Bind(scope constructs.Construct, options *iotevents.ActionBindOptions) *iotevents.ActionConfig {

results in panic: action._bind is not a function.

Alternatively, is there another way to achieve this?

Use Case

I have no way to extend the functionality here, except first write a Typescript class.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CDK version used

2.73.0

Environment details (OS name and version, etc.)

macOS 13.3

karl-dau avatar Apr 09 '23 08:04 karl-dau

I believe the Bind method is supposed to be internal and not to be exported.

What is your use case? Can you share more about your code?

pahud avatar Apr 11 '23 11:04 pahud

@pahud I am trying to add the SNS Action (which is not currently implemented for the L2 construct) using my own Go code. I also cannot downcast the L2 DetectorModel construct because DetectorModel.(CfnDetectorModel).DetectorModelDefinition().(CfnDetectorModel.DetectorModelDefinitionProperty) does not work, seeing as the jsiiProxy object can't be type asserted to DetectorModelDefinitionProperty.

Any other ideas?

karl-dau avatar Apr 11 '23 12:04 karl-dau

Issue Analysis

The Interface Implementation Problem

In TypeScript, this works:

// Interface definition
interface IAction {
  _bind(): ActionConfig;  // marked @internal
}

// Implementation (works even with @internal)
class MyAction implements IAction {
  _bind() { return {...}; }
}

In Go, this fails:

// Generated Go interface (missing _bind due to @internal)
type IAction interface {
  // _bind method is NOT generated
}

// Cannot implement - Go requires ALL interface methods
type MyAction struct{}
func (a *MyAction) _bind() ActionConfig { return ... } // Method doesn't exist in interface!

Purpose and Why

The need to create an SNS Action for IoT Events because:

  1. Missing Functionality: CDK doesn't provide an SNS action for IoT Events L2 constructs
  2. Extensibility: Rather than waiting for AWS to add it, they want to implement it themselves
  3. Go Preference: They're working in Go, not TypeScript

The Fundamental Issue

Without exporting _bind, Go developers have zero extensibility for IoT Events actions. They're completely locked out of creating custom actions, which defeats the purpose of having a public IAction interface.

The interface exists to enable extensibility, but the @internal annotation accidentally breaks that extensibility for non-TypeScript languages.

pahud avatar Sep 05 '25 15:09 pahud

transferring to jsii for inputs from the maintainers.

pahud avatar Sep 05 '25 15:09 pahud