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

Allow fixed string input to CW Event #1198

Closed
mattmcclean opened this issue Nov 17, 2018 · 5 comments · Fixed by #1570
Closed

Allow fixed string input to CW Event #1198

mattmcclean opened this issue Nov 17, 2018 · 5 comments · Fixed by #1570
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions feature-request A feature should be added or improved.

Comments

@mattmcclean
Copy link
Contributor

I would like to use CDK to trigger the execution of a Step Function state machine on a periodic basis. Step functions can take input provided by the CloudWatch event however it seems that the Event resource only modifies the event object via a template rather than provide a static JSON text as the input field.

Today I have had to use the underlying cloudformation resources to do this with the "input" field. Would be nice to be able to do this with the L2 construct for Event.

      /** Create the CW Event */
      new events.cloudformation.RuleResource(this, 'EveryEveningEvent', {
        roleArn: ruleRole.roleArn,
        scheduleExpression: props.scheduleExpression,
        targets: [
            {
                arn: statemachine.stateMachineArn,
                roleArn: ruleRole.roleArn,
                id: 'StepMachineTarget',
                input: "{ \"NotebookName\": \"" + props.notebookName + "\", \"EmailAddress\": \"" + props.emailAddress + "\" }"
            }
        ]
      });
@rix0rrr rix0rrr added @aws-cdk/aws-stepfunctions Related to AWS StepFunctions feature-request A feature should be added or improved. labels Nov 19, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 19, 2018

I'm not 100% up to date on this API, but looking at it, wouldn't the following work?

const rule = new Rule(this, 'Rule', { ... });
const stateMachine = new StateMachine(this, 'SM', { ... });

rule.addTargeT(stateMachine, {
  jsonTemplate: {
    NotebookName: props.notebookName,
    EmailAddress: props.emailAddress,
  },
});

If not, why not?

@mattmcclean
Copy link
Contributor Author

I tried this but it gave me the following error:

While synthesizing CdkSagemakerNotebookWorkflowStack/MySageMakerStopNotebookWorkflow/ScheduledRule/Resource: Supplied properties not correct for "RuleResourceProps"
  targets: element 0: supplied properties not correct for "TargetProperty"
    inputTransformer: supplied properties not correct for "InputTransformerProperty"
      inputTemplate: {} should be a string

I think it is because it is trying to fill in the InputTemplate field of the EventRuleResource rather than the Input field which accepts static text.

@eladb
Copy link
Contributor

eladb commented Nov 22, 2018

jsonTemplate expects a JSON string, not a JSON object (probably something we can automatically determine and avoid the grief). Can you try this?

const rule = new Rule(this, 'Rule', { ... });
const stateMachine = new StateMachine(this, 'SM', { ... });

rule.addTarget(stateMachine, {
  jsonTemplate: JSON.stringify({
    NotebookName: props.notebookName,
    EmailAddress: props.emailAddress,
  }),
});

@mattmcclean
Copy link
Contributor Author

I have tried this out and it works fine. Thanks!

@eladb
Copy link
Contributor

eladb commented Dec 6, 2018

Reopening, we should change the type of jsonTemplate from any to string.

@eladb eladb reopened this Dec 6, 2018
rix0rrr added a commit that referenced this issue Jan 18, 2019
They will be JSONified automatically.

Fixes #1198.
rix0rrr added a commit that referenced this issue Jan 22, 2019
Fixes the following things for CloudWatch events:

* Support newlines in CloudWatch Events textTemplate as intended, by making a newline-separated list of JSON strings. Fixes #1514.
*  `jsonTemplate` now accepts arbitrary objects. They will be JSONified automatically. Fixes #1198.
* Explicitly implement `IEventRuleTarget` on stepfunctions StateMachine so that Java/.NET users can trigger StateMachines using CloudWatch Events. Fixes part of #1275.
sam-goodwin pushed a commit that referenced this issue Jan 28, 2019
Fixes the following things for CloudWatch events:

* Support newlines in CloudWatch Events textTemplate as intended, by making a newline-separated list of JSON strings. Fixes #1514.
*  `jsonTemplate` now accepts arbitrary objects. They will be JSONified automatically. Fixes #1198.
* Explicitly implement `IEventRuleTarget` on stepfunctions StateMachine so that Java/.NET users can trigger StateMachines using CloudWatch Events. Fixes part of #1275.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants