-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstateMachineRequest.ts
More file actions
60 lines (58 loc) · 2.48 KB
/
stateMachineRequest.ts
File metadata and controls
60 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* eslint-disable max-len */
/**
* @returns API Gateway request mapping template for StartExecution payloads.
*/
export const stateMachineRequestTemplate = (stateMachineArn: string) => {
return `## Velocity Template used for API Gateway request mapping template
## "@@" is used here as a placeholder for '"' to avoid using escape characters.
#set($includeHeaders = true)
#set($includeQueryString = true)
#set($includePath = true)
#set($requestContext = '')
#set($inputString = '')
#set($allParams = $input.params())
#set($allParams.header.apigw-request-id = $context.requestId)
{
"stateMachineArn": "${stateMachineArn}",
#set($inputString = "$inputString,@@body@@: $input.body")
#if ($includeHeaders)
#set($inputString = "$inputString, @@headers@@:{")
#foreach($paramName in $allParams.header.keySet())
#set($inputString = "$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.header.get($paramName))@@")
#if($foreach.hasNext)
#set($inputString = "$inputString,")
#end
#end
#set($inputString = "$inputString }")
#end
#if ($includeQueryString)
#set($inputString = "$inputString, @@queryStringParameters@@:{")
#foreach($paramName in $allParams.querystring.keySet())
#set($inputString = "$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.querystring.get($paramName))@@")
#if($foreach.hasNext)
#set($inputString = "$inputString,")
#end
#end
#set($inputString = "$inputString }")
#end
#if ($includePath)
#set($inputString = "$inputString, @@pathParameters@@:{")
#foreach($paramName in $allParams.path.keySet())
#set($inputString = "$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.path.get($paramName))@@")
#if($foreach.hasNext)
#set($inputString = "$inputString,")
#end
#end
#set($inputString = "$inputString }")
#end
## Check if the request context should be included as part of the execution input
#if($requestContext && !$requestContext.empty)
#set($inputString = "$inputString,")
#set($inputString = "$inputString @@requestContext@@: $requestContext")
#end
#set($inputString = "$inputString}")
#set($inputString = $inputString.replaceAll("@@",'"'))
#set($len = $inputString.length() - 1)
"input": "{$util.escapeJavaScript($inputString.substring(1,$len))}"
}`
}