Skip to content
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

fix(aws-lambda): remove aws lambda plugin init function #11528

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions kong/db/dao/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,29 +355,5 @@ function Plugins:get_handlers()
return list
end

function Plugins:execute_plugin_init()
local handlers, err = self:get_handlers()
if not handlers then
return nil, err
end

local errors

for _, handler in ipairs(handlers) do
if implements(handler.handler, "init") then
local ok, err = pcall(handler.handler.init, handler.handler)
if not ok then
errors = errors or {}
errors[#errors + 1] = "on plugin '" .. handler.name .. "': " .. tostring(err)
end
end
end

if errors then
return nil, "error executing plugin init: " .. table.concat(errors, "; ")
end

return true
end

return Plugins
2 changes: 0 additions & 2 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ function Kong.init()
-- Load plugins as late as possible so that everything is set up
assert(db.plugins:load_plugin_schemas(config.loaded_plugins))

assert(db.plugins:execute_plugin_init())

if is_stream_module then
stream_api.load_handlers()
end
Expand Down
26 changes: 16 additions & 10 deletions kong/plugins/aws-lambda/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ local build_request_payload = request_util.build_request_payload
local extract_proxy_response = request_util.extract_proxy_response

local aws = require("resty.aws")
local AWS_GLOBAL_CONFIG
local AWS_REGION do
AWS_REGION = os.getenv("AWS_REGION") or os.getenv("AWS_DEFAULT_REGION")
end
local aws_config = require("resty.aws.config")
-- Fetch and cache env vars during init phase
local AWS_GLOBAL_CONFIG = aws_config.get_config()
local AWS
local LAMBDA_SERVICE_CACHE = setmetatable({}, { __mode = "k" })

Expand All @@ -35,20 +34,27 @@ local AWSLambdaHandler = {
VERSION = meta.version
}

function AWSLambdaHandler:init()
AWS_GLOBAL_CONFIG = require("resty.aws.config").global
AWS = aws()
end


function AWSLambdaHandler:access(conf)
-- The region in plugin configuraion has higher priority
-- than the one in environment variable
local region = conf.aws_region or AWS_REGION
local region = conf.aws_region or AWS_GLOBAL_CONFIG.region
if not region then
return error("no region specified")
end

if not aws_config.global then
-- Fetch region from metadata service, or from
-- environment variable
AWS_GLOBAL_CONFIG = require("resty.aws.config").global
end

if not AWS then
AWS = aws({
region = region
})
end

local host = conf.host or fmt("lambda.%s.amazonaws.com", region)

local port = conf.port or 443
Expand Down
Loading