From 54192f592ae2683de15a61a072f68a25ad268557 Mon Sep 17 00:00:00 2001 From: Dax Chen Date: Wed, 14 Sep 2016 15:36:16 +0800 Subject: [PATCH] Fix YML example code: strings should be quoted In YML, strings containing :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, ` must be quoted. Without the quotes, deployments will fail at `AWS::ApiGateway::Method` step. I've been trying to use the custom request template after upgrading to v1.0, and finally found the correct syntax, lol. Let me know if any correction is needed, and if more/less examples are preferred. --- docs/02-providers/aws/events/01-apigateway.md | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/02-providers/aws/events/01-apigateway.md b/docs/02-providers/aws/events/01-apigateway.md index 5ffaf4360..c021e8bf5 100644 --- a/docs/02-providers/aws/events/01-apigateway.md +++ b/docs/02-providers/aws/events/01-apigateway.md @@ -71,12 +71,34 @@ functions: path: whatever request: template: - text/xhtml: { "stage" : "$context.stage" } - application/json: { "httpMethod" : "$context.httpMethod" } + text/xhtml: '{ "stage" : "$context.stage" }' + application/json: '{ "httpMethod" : "$context.httpMethod" }' ``` **Note:** The templates are defined as plain text here. However you can also reference an external file with the help of the `${file(templatefile)}` syntax. +**Note 2:** In .yml, strings containing `:`, `{`, `}`, `[`, `]`, `,`, `&`, `*`, `#`, `?`, `|`, `-`, `<`, `>`, `=`, `!`, `%`, `@`, `` ` `` must be quoted. + +If you want to map querystrings to the event object, you can use the `$input.params('hub.challenge')` syntax from API Gateway, as follows: + +```yml +functions: + create: + handler: posts.create + events: + - http: + method: get + path: whatever + request: + template: + application/json: '{ "foo" : "$input.params(''bar'')" }' +``` + +**Note:** Notice when using single-quoted strings, any single quote `'` inside its contents must be doubled (`''`) to escape it. +You can then access the query string `https://example.com/dev/whatever?bar=123` by `event.foo` in the lambda function. +If you want to spread a string into multiple lines, you can use the `>` or `|` syntax, but the following strings have to be all indented with the same amount, [read more about `>` syntax](http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines). + + ### Pass Through Behavior API Gateway provides multiple ways to handle requests where the Content-Type header does not match any of the specified mapping templates. When this happens, the request payload will either be passed through the integration request *without transformation* or rejected with a `415 - Unsupported Media Type`, depending on the configuration.