Skip to content

Commit cfe2512

Browse files
committed
feat: add docs for s3 request & response templates
1 parent d9cd185 commit cfe2512

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

README.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ This Serverless Framework plugin supports the AWS service proxy integration feat
1616
- [Customizing responses](#customizing-responses)
1717
- [S3](#s3)
1818
- [Customizing request parameters](#customizing-request-parameters-1)
19+
- [Customizing request templates](#customizing-request-templates)
1920
- [Customize the Path Override in API Gateway](#customize-the-path-override-in-api-gateway)
2021
- [Can use greedy, for deeper Folders](#can-use-greedy--for-deeper-folders)
21-
- [SNS](#sns)
2222
- [Customizing responses](#customizing-responses-1)
23+
- [SNS](#sns)
24+
- [Customizing responses](#customizing-responses-2)
2325
- [DynamoDB](#dynamodb)
2426
- [EventBridge](#eventbridge)
2527
- [Common API Gateway features](#common-api-gateway-features)
@@ -290,6 +292,29 @@ custom:
290292
'integration.request.header.cache-control': "'public, max-age=31536000, immutable'"
291293
```
292294

295+
#### Customizing request templates
296+
297+
If you'd like use custom [API Gateway request templates](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html), you can do so like so:
298+
299+
```yml
300+
custom:
301+
apiGatewayServiceProxies:
302+
- s3:
303+
path: /s3
304+
method: get
305+
action: GetObject
306+
bucket:
307+
Ref: S3Bucket
308+
request:
309+
template:
310+
application/json: |
311+
#set ($specialStuff = $context.request.header.x-special)
312+
#set ($context.requestOverride.path.object = $specialStuff.replaceAll('_', '-'))
313+
{}
314+
```
315+
316+
Note that if the client does not provide a `Content-Type` header in the request, [ApiGateway defaults to `application/json`](https://docs.aws.amazon.com/apigateway/latest/developerguide/integration-passthrough-behaviors.html).
317+
293318
#### Customize the Path Override in API Gateway
294319

295320
Added the new customization parameter that lets the user set a custom Path Override in API Gateway other than the `{bucket}/{object}`
@@ -348,6 +373,33 @@ custom:
348373

349374
This will translate for example `/s3/a/b/c` to `a/b/c.xml`
350375

376+
#### Customizing responses
377+
378+
You can get a simple customization of the responses by providing a template for the possible responses. The template is assumed to be `application/json`.
379+
380+
```yml
381+
custom:
382+
apiGatewayServiceProxies:
383+
- s3:
384+
path: /s3
385+
method: post
386+
action: PutObject
387+
bucket:
388+
Ref: S3Bucket
389+
key: static-key.json
390+
response:
391+
template:
392+
# `success` is used when the integration response is 200
393+
success: |-
394+
{ "message: "accepted" }
395+
# `clientError` is used when the integration response is 400
396+
clientError: |-
397+
{ "message": "there is an error in your request" }
398+
# `serverError` is used when the integration response is 500
399+
serverError: |-
400+
{ "message": "there was an error handling your request" }
401+
```
402+
351403
### SNS
352404
353405
Sample syntax for SNS proxy in `serverless.yml`.

0 commit comments

Comments
 (0)