Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to extract [common?] fields from events #38

Closed
eladb opened this issue Jun 5, 2018 · 2 comments
Closed

Make it easier to extract [common?] fields from events #38

eladb opened this issue Jun 5, 2018 · 2 comments

Comments

@eladb
Copy link
Contributor

eladb commented Jun 5, 2018

The input transformation supported by eventRule.addTarget(target, inputTransformation) requires deep knowledge of how source events look.

For example, to trigger an SNS topic every time an EC2 instance changes its state, users currently need to write:

const instance = new ec2.Instance(this, 'MyInstance');
instance.onStateChange().addTarget(topic, {
  textTemplate: 'Instance <instance> changed state to <state>',
  pathsMap: {
    state: '$.detail.state', 
    instance : '$.detail.instance-id'
  }
});

This means that users must know exactly how an "EC2 Instance State-change Notification" looks like. Ideally that should be an implementation detail of the ec2.Instance class.

See #27 for context

@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 5, 2018

Wouldn't it be great though if we could do something like:

instance.onStateChange().addTarget(topic, {
  textTemplate: 'Instance <instance> changed state to <state>',
  pathsMap: {
    state: StateChangeEvent.detail.state,
    instance : StateChangeEvent.detail.instanceId
  }
});

Where I both

  • a) discover what fields are available; and
  • b) can't make mistakes.

Obviously, now I need to know I need to instantiate a StateChangeEvent, but even that could be fixed like so:

instance.onStateChange().addTarget(topic, {
  textTemplate: 'Instance <instance> changed state to <state>',
}).substituting(event => ({
    state: event.detail.state,
    instance: event.detail.instanceId
}));

@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 11, 2018

Although the latter will be hampered by the fact that jsii doesn't support Lambdas (...or does it?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants