Commit be672a9
committed
feat(sqs): add request template support for sqs
Allows the addition of `request.template.<content-type>` to `serverless.yml` under `apiGatewayServiceProxies`.
Changes the approach to passing basic `Action` and `MessageBody` values by passing them in the POST request payload instead of via querystrings. This means that the prior default `RequestParameters` have been replaced with a single default which sets the `Content-Type` to `application/x-www-form-urlencoded`.
An example config which satisfies the requirements for an SQS FIFO queue follows.
Given a request payload of:
```json
{
"event_type": "message",
"event_id": "ABC123",
"message": "Hello!"
}
```
Then the following config inside `serverless.yml`:
```yaml
apiGatewayServiceProxies:
- sqs:
path: /{version}/slack/receiver
method: post
queueName:
Fn::GetAtt:
- eventQueue
- "QueueName"
request:
template:
application/json: |-
#set ($body = $util.parseJson($input.body))
Action=SendMessage##
&MessageGroupId=$util.urlEncode($body.event_type)##
&MessageDeduplicationId=$util.urlEncode($body.event_id)##
&MessageAttribute.1.Name=$util.urlEncode("X-Custom-Signature")##
&MessageAttribute.1.Value.DataType=String##
&MessageAttribute.1.Value.StringValue=$util.urlEncode($input.params("X-Custom-Signature"))##
&MessageBody=$util.urlEncode($input.body)
```
Will produce the following request body (substituting some values with tags):
```
Action=SendMessage&MessageGroupId=message&MessageDeduplicationId=ABC123&MessageAttribute.1.Name=X-Custom-Signature&MessageAttribute.1.Value.DataType=String&MessageAttribute.1.Value.StringValue=<related-header-value>&MessageBody=<url-encoded-request-payload>
```
It is usually possible to omit the url encoding of the `$input.body` as SQS does not seem to care too much about that, but I have not tested with any potentially problematic characters.1 parent 9121de8 commit be672a9
File tree
4 files changed
+198
-22
lines changed- lib
- apiGateway
- package/sqs
4 files changed
+198
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
| 251 | + | |
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1555 | 1555 | | |
1556 | 1556 | | |
1557 | 1557 | | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
1558 | 1615 | | |
1559 | 1616 | | |
1560 | 1617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
103 | 118 | | |
104 | 119 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | | - | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | | - | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| 178 | + | |
176 | 179 | | |
177 | | - | |
178 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
179 | 184 | | |
180 | | - | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| |||
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
| 279 | + | |
275 | 280 | | |
276 | | - | |
277 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
278 | 285 | | |
279 | | - | |
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
| |||
399 | 405 | | |
400 | 406 | | |
401 | 407 | | |
| 408 | + | |
402 | 409 | | |
403 | | - | |
404 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
405 | 414 | | |
406 | | - | |
407 | 415 | | |
408 | 416 | | |
409 | 417 | | |
| |||
486 | 494 | | |
487 | 495 | | |
488 | 496 | | |
| 497 | + | |
489 | 498 | | |
490 | | - | |
491 | | - | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
492 | 503 | | |
493 | | - | |
494 | 504 | | |
495 | 505 | | |
496 | 506 | | |
| |||
573 | 583 | | |
574 | 584 | | |
575 | 585 | | |
| 586 | + | |
576 | 587 | | |
577 | | - | |
578 | | - | |
| 588 | + | |
579 | 589 | | |
580 | 590 | | |
581 | 591 | | |
582 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
583 | 686 | | |
584 | 687 | | |
585 | 688 | | |
| |||
0 commit comments