1
1
import {
2
- FieldUtils ,
3
2
IntegrationPattern ,
4
- renderJsonPath ,
5
- TaskStateBaseProps ,
6
3
} from '@aws-cdk/aws-stepfunctions' ;
7
4
import { Aws } from '@aws-cdk/core' ;
8
5
9
- /**
10
- * Represents a service integration call to Step Functions
11
- */
12
- export interface TaskStateConfig extends TaskStateBaseProps {
13
- /**
14
- * The ARN of resource that represents the work to be executed
15
- */
16
- readonly resourceArn : string ;
17
-
18
- /**
19
- * Parameters pass a collection of key-value pairs, either static values or
20
- * JSON path expressions that select from the input.
21
- *
22
- * @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters
23
- *
24
- * @default - No parameters
25
- */
26
- readonly parameters ?: { [ name : string ] : any } ;
27
- }
28
-
29
- /**
30
- * Generates the State JSON to define a task state
31
- */
32
- export function taskStateJson ( config : TaskStateConfig ) : any {
33
- return {
34
- Type : 'Task' ,
35
- Comment : config . comment ,
36
- Resource : config . resourceArn ,
37
- Parameters : config . parameters && FieldUtils . renderObject ( config . parameters ) ,
38
- TimeoutSeconds : config . timeout ?. toSeconds ( ) ,
39
- HeartbeatSeconds : config . heartbeat ?. toSeconds ( ) ,
40
- InputPath : renderJsonPath ( config . inputPath ) ,
41
- OutputPath : renderJsonPath ( config . outputPath ) ,
42
- ResultPath : renderJsonPath ( config . resultPath ) ,
43
- } ;
44
- }
45
-
46
6
/**
47
7
* Verifies that a validation pattern is supported for a service integration
48
8
*
@@ -60,15 +20,16 @@ export function validatePatternSupported(integrationPattern: IntegrationPattern,
60
20
*
61
21
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html
62
22
*/
63
- const resourceArnSuffix = new Map < IntegrationPattern , string > ( ) ;
64
- resourceArnSuffix . set ( IntegrationPattern . REQUEST_RESPONSE , '' ) ;
65
- resourceArnSuffix . set ( IntegrationPattern . RUN_JOB , '.sync' ) ;
66
- resourceArnSuffix . set ( IntegrationPattern . WAIT_FOR_TASK_TOKEN , '.waitForTaskToken' ) ;
23
+ const resourceArnSuffix : Record < IntegrationPattern , string > = {
24
+ [ IntegrationPattern . REQUEST_RESPONSE ] : '' ,
25
+ [ IntegrationPattern . RUN_JOB ] : '.sync' ,
26
+ [ IntegrationPattern . WAIT_FOR_TASK_TOKEN ] : '.waitForTaskToken' ,
27
+ } ;
67
28
68
- export function getResourceArn ( service : string , api : string , integrationPattern : IntegrationPattern ) : string {
29
+ export function integrationResourceArn ( service : string , api : string , integrationPattern : IntegrationPattern ) : string {
69
30
if ( ! service || ! api ) {
70
31
throw new Error ( "Both 'service' and 'api' must be provided to build the resource ARN." ) ;
71
32
}
72
33
return `arn:${ Aws . PARTITION } :states:::${ service } :${ api } ` +
73
- ( integrationPattern ? resourceArnSuffix . get ( integrationPattern ) : '' ) ;
34
+ ( integrationPattern ? resourceArnSuffix [ integrationPattern ] : '' ) ;
74
35
}
0 commit comments