@@ -532,7 +532,24 @@ The following snippet invokes a Lambda Function with the state input as the payl
532
532
by referencing the ` $ ` path.
533
533
534
534
``` ts
535
- new sfn .Task (this , ' Invoke with state input' );
535
+ import * as lambda from ' @aws-cdk/aws-lambda' ;
536
+ import * as sfn from ' @aws-cdk/aws-stepfunctions' ;
537
+ import * as tasks from ' @aws-cdk/aws-stepfunctions-tasks' ;
538
+
539
+ const myLambda = new lambda .Function (this , ' my sample lambda' , {
540
+ code: Code .fromInline (` exports.handler = async () => {
541
+ return {
542
+ statusCode: '200',
543
+ body: 'hello, world!'
544
+ };
545
+ }; ` ),
546
+ runtime: Runtime .NODEJS_12_X ,
547
+ handler: ' index.handler' ,
548
+ });
549
+
550
+ new tasks .LambdaInvoke (this , ' Invoke with state input' , {
551
+ lambdaFunction: myLambda ,
552
+ });
536
553
```
537
554
538
555
When a function is invoked, the Lambda service sends [ these response
@@ -545,27 +562,25 @@ The following snippet invokes a Lambda Function by referencing the `$.Payload` p
545
562
to reference the output of a Lambda executed before it.
546
563
547
564
``` ts
548
- new sfn .Task (this , ' Invoke with empty object as payload' , {
549
- task: new tasks .RunLambdaTask (myLambda , {
550
- payload: sfn .TaskInput .fromObject ({})
551
- }),
565
+ new tasks .LambdaInvoke (this , ' Invoke with empty object as payload' , {
566
+ lambdaFunction: myLambda ,
567
+ payload: sfn .TaskInput .fromObject ({}),
552
568
});
553
569
554
- new sfn . Task ( this , ' Invoke with payload field in the state input' , {
555
- task: new tasks .RunLambdaTask ( myOtherLambda , {
556
- payload: sfn . TaskInput . fromDataAt ( ' $.Payload ' ) ,
557
- } ),
570
+ // use the output of myLambda as input
571
+ new tasks .LambdaInvoke ( this , ' Invoke with payload field in the state input ' , {
572
+ lambdaFunction: myOtherLambda ,
573
+ payload: sfn . TaskInput . fromDataAt ( ' $.Payload ' ),
558
574
});
559
575
```
560
576
561
577
The following snippet invokes a Lambda and sets the task output to only include
562
578
the Lambda function response.
563
579
564
580
``` ts
565
- new sfn .Task (this , ' Invoke and set function response as task output' , {
566
- task: new tasks .RunLambdaTask (myLambda , {
567
- payload: sfn .TaskInput .fromDataAt (' $' ),
568
- }),
581
+ new tasks .LambdaInvoke (this , ' Invoke and set function response as task output' , {
582
+ lambdaFunction: myLambda ,
583
+ payload: sfn .TaskInput .fromDataAt (' $' ),
569
584
outputPath: ' $.Payload' ,
570
585
});
571
586
```
@@ -581,15 +596,14 @@ The following snippet invokes a Lambda with the task token as part of the input
581
596
to the Lambda.
582
597
583
598
``` ts
584
- const task = new sfn .Task (stack , ' Invoke with callback' , {
585
- task: new tasks .RunLambdaTask (myLambda , {
586
- integrationPattern: sfn .ServiceIntegrationPattern .WAIT_FOR_TASK_TOKEN ,
587
- payload: {
588
- token: sfn .Context .taskToken ,
589
- input: sfn .TaskInput .fromDataAt (' $.someField' ),
590
- }
591
- })
592
- });
599
+ new tasks .LambdaInvoke (stack , ' Invoke with callback' , {
600
+ lambdaFunction: myLambda ,
601
+ integrationPattern: sfn .IntegrationPattern .WAIT_FOR_TASK_TOKEN ,
602
+ payload: sfn .TaskInput .fromObject ({
603
+ token: sfn .Context .taskToken ,
604
+ input: sfn .Data .stringAt (' $.someField' ),
605
+ }),
606
+ });
593
607
```
594
608
595
609
⚠️ The task will pause until it receives that task token back with a ` SendTaskSuccess ` or ` SendTaskFailure `
@@ -677,28 +691,28 @@ You can call the [`Publish`](https://docs.aws.amazon.com/sns/latest/api/API_Publ
677
691
678
692
``` ts
679
693
import * as sns from ' @aws-cdk/aws-sns' ;
694
+ import * as sfn from ' @aws-cdk/aws-stepfunctions' ;
695
+ import * as tasks from ' @aws-cdk/aws-stepfunctions-tasks' ;
680
696
681
697
// ...
682
698
683
699
const topic = new sns .Topic (this , ' Topic' );
684
700
685
701
// Use a field from the execution data as message.
686
- const task1 = new sfn .Task (this , ' Publish1' , {
687
- task: new tasks .PublishToTopic (topic , {
688
- integrationPattern: sfn .ServiceIntegrationPattern .FIRE_AND_FORGET ,
689
- message: TaskInput .fromDataAt (' $.state.message' ),
690
- })
702
+ const task1 = new tasks .SnsPublish (this , ' Publish1' , {
703
+ topic ,
704
+ integrationPattern: sfn .IntegrationPattern .REQUEST_RESPONSE ,
705
+ message: sfn .TaskInput .fromDataAt (' $.state.message' ),
691
706
});
692
707
693
708
// Combine a field from the execution data with
694
709
// a literal object.
695
- const task2 = new sfn .Task (this , ' Publish2' , {
696
- task: new tasks .PublishToTopic (topic , {
697
- message: TaskInput .fromObject ({
698
- field1: ' somedata' ,
699
- field2: Data .stringAt (' $.field2' ),
700
- })
701
- })
710
+ const task2 = new tasks .SnsPublish (this , ' Publish2' , {
711
+ topic ,
712
+ message: sfn .TaskInput .fromObject ({
713
+ field1: ' somedata' ,
714
+ field2: sfn .Data .stringAt (' $.field2' ),
715
+ })
702
716
});
703
717
```
704
718
@@ -740,31 +754,27 @@ You can call the [`SendMessage`](https://docs.aws.amazon.com/AWSSimpleQueueServi
740
754
to send a message to an SQS queue.
741
755
742
756
``` ts
757
+ import * as sfn from ' @aws-cdk/aws-stepfunctions' ;
758
+ import * as tasks from ' @aws-cdk/aws-stepfunctions-tasks' ;
743
759
import * as sqs from ' @aws-cdk/aws-sqs' ;
744
760
745
761
// ...
746
762
747
- const queue = new sns .Queue (this , ' Queue' );
763
+ const queue = new sqs .Queue (this , ' Queue' );
748
764
749
765
// Use a field from the execution data as message.
750
- const task1 = new sfn .Task (this , ' Send1' , {
751
- task: new tasks .SendToQueue (queue , {
752
- messageBody: TaskInput .fromDataAt (' $.message' ),
753
- // Only for FIFO queues
754
- messageGroupId: ' 1234'
755
- })
766
+ const task1 = new tasks .SqsSendMessage (this , ' Send1' , {
767
+ queue ,
768
+ messageBody: sfn .TaskInput .fromDataAt (' $.message' ),
756
769
});
757
770
758
771
// Combine a field from the execution data with
759
772
// a literal object.
760
- const task2 = new sfn .Task (this , ' Send2' , {
761
- task: new tasks .SendToQueue (queue , {
762
- messageBody: TaskInput .fromObject ({
763
- field1: ' somedata' ,
764
- field2: Data .stringAt (' $.field2' ),
765
- }),
766
- // Only for FIFO queues
767
- messageGroupId: ' 1234'
768
- })
773
+ const task2 = new tasks .SqsSendMessage (this , ' Send2' , {
774
+ queue ,
775
+ messageBody: sfn .TaskInput .fromObject ({
776
+ field1: ' somedata' ,
777
+ field2: sfn .Data .stringAt (' $.field2' ),
778
+ }),
769
779
});
770
780
```
0 commit comments