Make Response API Gateway Compliant

This commit is contained in:
Rowell Belen 2017-03-10 23:24:09 -07:00
parent ca1eee3e05
commit a53893e33b
4 changed files with 12 additions and 6 deletions

View File

@ -56,10 +56,11 @@ functions:
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# - http:
# path: users/create
# method: get
events:
- http:
path: hello
method: get
cors: true
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic

View File

@ -7,6 +7,6 @@ import groovy.transform.builder.Builder
@CompileStatic
class ApiGatewayResponse {
int statusCode
Response body
String body
Map<String, String> headers
}

View File

@ -19,7 +19,7 @@ class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse>
.build()
return ApiGatewayResponse.builder()
.statusCode(200)
.body(responseBody)
.body(responseBody.toJson())
.headers(['X-Powered-By': 'AWS Lambda & serverless'])
.build()
}

View File

@ -1,5 +1,6 @@
package com.serverless
import groovy.json.JsonOutput
import groovy.transform.CompileStatic
import groovy.transform.builder.Builder
@ -8,4 +9,8 @@ import groovy.transform.builder.Builder
class Response {
Object message
Map<String, Object> input
String toJson() {
return JsonOutput.prettyPrint(JsonOutput.toJson(this))
}
}