-
Notifications
You must be signed in to change notification settings - Fork 80
feat(sqs): add request template support for sqs #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sqs): add request template support for sqs #86
Conversation
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.
Co-authored-by: Geoff Baskwill <me@geoffbaskwill.ca>
|
@sambauers
Does this mean to include a breaking change? If so, we would like to avoid that. |
|
@horike37 I’ll see if I can make this backward compatible and update once I have a solution. |
|
Thanks! |
|
@horike37 I've attempted to cater for existing implementations by passing any querystring request params into the default request body. The limitation is that an implementation can not specify querystring request params and a custom request body. If both are present, the custom request body will always be used instead of the backward-compatible mapping. I've added two more tests to account for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this update 👍 LGTM.
|
@sambauers Can you take a look? Otherwise, This PR will be reverted for fixing this failure. |
|
🎉 This PR is included in version 1.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Allows the addition of
request.template.<content-type>toserverless.ymlunderapiGatewayServiceProxies.Changes the approach to passing basic
ActionandMessageBodyvalues by passing them in the POST request payload instead of via querystrings. This means that the prior defaultRequestParametershave been replaced with a single default which sets theContent-Typetoapplication/x-www-form-urlencoded.An example config which satisfies the requirements for an SQS FIFO queue follows.
Given a request payload of:
{ "event_type": "message", "event_id": "ABC123", "message": "Hello!" }Then the following config inside
serverless.yml:Will produce the following request body (substituting some values with tags):
It is usually possible to omit the url encoding of the
$input.bodyas SQS does not seem to care too much about that, but I have not tested with any potentially problematic characters.This PR is in response to #80