@@ -23,6 +23,9 @@ module.exports = {
23
23
let Name ;
24
24
let EventBusName ;
25
25
let IamRole ;
26
+ let InputTransformer ;
27
+ let InputPathsMap ;
28
+ let InputTemplate ;
26
29
27
30
if ( typeof eventRule === 'object' ) {
28
31
if ( ! eventRule . event ) {
@@ -41,14 +44,17 @@ module.exports = {
41
44
}
42
45
Input = eventRule . input ;
43
46
InputPath = eventRule . inputPath ;
47
+ InputTransformer = eventRule . inputTransformer ;
48
+ InputPathsMap = InputTransformer && eventRule . inputTransformer . inputPathsMap ;
49
+ InputTemplate = InputTransformer && eventRule . inputTransformer . inputTemplate ;
44
50
Description = eventRule . description ;
45
51
Name = eventRule . name ;
46
52
EventBusName = JSON . stringify ( eventRule . eventBusName ) ;
47
53
IamRole = eventRule . iamRole ;
48
54
49
- if ( Input && InputPath ) {
55
+ if ( [ Input , InputPath , InputTransformer ] . filter ( Boolean ) . length > 1 ) {
50
56
const errorMessage = [
51
- 'You can\'t set both input & inputPath properties at the' ,
57
+ 'You can\'t set input, inputPath and inputTransformer properties at the' ,
52
58
'same time for cloudwatch events.' ,
53
59
'Please check the AWS docs for more info' ,
54
60
] . join ( '' ) ;
@@ -62,6 +68,16 @@ module.exports = {
62
68
// escape quotes to favor JSON.parse
63
69
Input = Input . replace ( / \" / g, '\\"' ) ; // eslint-disable-line
64
70
}
71
+
72
+ // no need to escape quotes in inputPathsMap
73
+ // because we add it as an object to the template
74
+ if ( InputPathsMap && typeof InputPathsMap === 'object' ) {
75
+ InputPathsMap = JSON . stringify ( InputPathsMap ) ;
76
+ }
77
+ if ( InputTemplate && typeof InputTemplate === 'string' ) {
78
+ // escape quotes to favor JSON.parse
79
+ InputTemplate = InputTemplate . replace ( / \" / g, '\\"' ) ; // eslint-disable-line
80
+ }
65
81
} else {
66
82
const errorMessage = [
67
83
`CloudWatch event of stateMachine "${ stateMachineName } " is not an object` ,
@@ -92,6 +108,10 @@ module.exports = {
92
108
"Targets": [{
93
109
${ Input ? `"Input": "${ Input . replace ( / \\ n | \\ r / g, '' ) } ",` : '' }
94
110
${ InputPath ? `"InputPath": "${ InputPath . replace ( / \r ? \n / g, '' ) } ",` : '' }
111
+ ${ InputTransformer ? `"InputTransformer": {
112
+ "InputPathsMap": ${ InputPathsMap } ,
113
+ "InputTemplate": "${ InputTemplate } "
114
+ },` : '' }
95
115
"Arn": { "Ref": "${ stateMachineLogicalId } " },
96
116
"Id": "${ cloudWatchId } ",
97
117
${ IamRole ? `"RoleArn":"${ IamRole } "` : `"RoleArn": {
0 commit comments