-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-lambda) Add support for setting the unhandled response code
Adds a new `unhandled_status` configuration option for the aws-lambda plugin. If set the response status will be overridden if the `X-Amzn-Function-Error` lambda invoke respoonse header was set to `Unhandled`. This gives a new feature to users of the plugin allowing their API to return non 20x codes. The previous functionality of responding with Amazon's Lambda Invoke unhandled response status of 200 (RequestResponse), 202 (Event), or 204 (DryRun) remains.
- Loading branch information
Showing
5 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local aws_lambda_schema = require "kong.plugins.aws-lambda.schema" | ||
local schemas = require "kong.dao.schemas_validation" | ||
local utils = require "kong.tools.utils" | ||
local validate_entity = schemas.validate_entity | ||
|
||
describe("Plugin: AWS Lambda (schema)", function() | ||
local DEFAULTS = { | ||
timeout = 60000, | ||
keepalive = 60000, | ||
aws_key = "my-key", | ||
aws_secret = "my-secret", | ||
aws_region = "us-east-1", | ||
function_name = "my-function", | ||
invocation_type = "RequestResponse", | ||
log_type = "Tail", | ||
port = 443, | ||
} | ||
|
||
it("accepts nil Unhandled Response Status Code", function() | ||
local entity = utils.table_merge(DEFAULTS, { unhandled_status = nil }) | ||
local ok, err = validate_entity(entity, aws_lambda_schema) | ||
assert.is_nil(err) | ||
assert.True(ok) | ||
end) | ||
|
||
it("accepts correct Unhandled Response Status Code", function() | ||
local entity = utils.table_merge(DEFAULTS, { unhandled_status = 412 }) | ||
local ok, err = validate_entity(entity, aws_lambda_schema) | ||
assert.is_nil(err) | ||
assert.True(ok) | ||
end) | ||
|
||
it("errors with Unhandled Response Status Code less than 100", function() | ||
local entity = utils.table_merge(DEFAULTS, { unhandled_status = 99 }) | ||
local ok, err = validate_entity(entity, aws_lambda_schema) | ||
assert.equal("unhandled_status must be within 100 - 999.", err.unhandled_status) | ||
assert.False(ok) | ||
end) | ||
|
||
it("errors with Unhandled Response Status Code greater than 999", function() | ||
local entity = utils.table_merge(DEFAULTS, { unhandled_status = 1000 }) | ||
local ok, err = validate_entity(entity, aws_lambda_schema) | ||
assert.equal("unhandled_status must be within 100 - 999.", err.unhandled_status) | ||
assert.False(ok) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters