Skip to content

Commit

Permalink
bring lambda up to speed
Browse files Browse the repository at this point in the history
  • Loading branch information
benwilson512 committed May 17, 2015
1 parent 08f6a61 commit f4eca68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions lib/ex_aws/lambda/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ defmodule ExAws.Lambda.Client do
By default this just forwards the request to the ExAws.Lambda.Request.request/4.
However, this can be overriden in your client to provide pre-request adjustments to headers, params, etc.
"""
defcallback request(data :: %{}, action :: atom, path :: binary)
defcallback request(data :: %{}, action :: atom, path :: binary, params :: Dict.t)
defcallback request(data :: %{}, action :: atom, path :: binary, params :: Dict.t, headers :: [{binary, binary}, ...])
defcallback request(client :: %{}, data :: %{}, action :: atom, path :: binary)
defcallback request(client :: %{}, data :: %{}, action :: atom, path :: binary, params :: Dict.t)
defcallback request(client :: %{}, data :: %{}, action :: atom, path :: binary, params :: Dict.t, headers :: [{binary, binary}, ...])

@doc "Retrieves the root AWS config for this client"
defcallback config_root() :: Keyword.t
Expand All @@ -190,14 +190,14 @@ defmodule ExAws.Lambda.Client do
unquote(boilerplate)

@doc false
def request(data, action, path, params \\ [], headers \\ []) do
ExAws.Lambda.Request.request(__MODULE__, action, path, data, params, headers)
def request(client, action, data, path, params \\ [], headers \\ []) do
ExAws.Lambda.Request.request(client, action, path, data, params, headers)
end

@doc false
def service, do: :lambda

defoverridable config_root: 0, request: 3, request: 4, request: 5
defoverridable config_root: 0, request: 4, request: 5, request: 6
end
end

Expand Down
40 changes: 20 additions & 20 deletions lib/ex_aws/lambda/impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,57 @@ defmodule ExAws.Lambda.Impl do
]

def add_permission(client, function_name, principal, action, statement_id, opts \\ []) do
opts
data = opts
|> normalize_opts
|> Map.merge(%{
"Action" => action,
"Principal" => principal,
"StatementId" => statement_id})
|> client.request(:add_permission, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy")
request(client, :add_permission, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy")
end

def create_event_source_mapping(client, function_name, event_source_arn, starting_position, opts \\ []) do
opts
data = opts
|> normalize_opts
|> Map.merge(%{
"FunctionName" => function_name,
"EventSourceArn" => event_source_arn,
"StartingPosition" => starting_position |> upcase})
|> client.request(:create_event_source_mapping, "/2015-03-31/event-source-mappings/")
request(client, :create_event_source_mapping, data, "/2015-03-31/event-source-mappings/")
end

def create_function(client, function_name, handler, zipfile, opts \\ []) do
opts
data ,opts
|> normalize_opts
|> Map.merge(%{
"FunctionName" => function_name,
"Handler" => handler,
"Code" => %{"ZipFile" => zipfile}})
|> client.request(:create_function, "/2015-03-31/functions")
request(client, :create_function, data, "/2015-03-31/functions")
end

def delete_event_source_mapping(client, source_mapping_uuid) do
client.request(%{}, :delete_event_source_mapping, "/2015-03-31/event-source-mappings/#{source_mapping_uuid}")
request(client, :delete_event_source_mapping, data, "/2015-03-31/event-source-mappings/#{source_mapping_uuid}")
end

def delete_function(client, function_name) do
client.request(%{}, :delete_function, "/2015-03-31/functions/#{function_name}")
request(client, :delete_function, data, "/2015-03-31/functions/#{function_name}")
end

def get_event_source_mapping(client, source_mapping_uuid) do
client.request(%{}, :get_event_source_mapping, "/2015-03-31/event-source-mappings/#{source_mapping_uuid}")
request(client, :get_event_source_mapping, data, "/2015-03-31/event-source-mappings/#{source_mapping_uuid}")
end

def get_function(client, function_name) do
client.request(%{}, :get_function, "/2015-03-31/functions/#{function_name}/versions/HEAD")
request(client, :get_function, data, "/2015-03-31/functions/#{function_name}/versions/HEAD")
end

def get_function_configuration(client, function_name) do
client.request(%{}, :get_function_configuration, "/2015-03-31/functions/#{function_name}/versions/HEAD/configuration")
request(client, :get_function_configuration, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/configuration")
end

def get_policy(client, function_name) do
client.request(%{}, :get_policy, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy")
request(client, :get_policy, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy")
end

def invoke(client, function_name, payload, client_context, opts \\ []) do
Expand All @@ -100,40 +100,40 @@ defmodule ExAws.Lambda.Impl do
header = {"X-Amz-Client-Context", context |> client.config[:json_codec].encode! |> Base.encode64}
[header | headers]
end
client.request(payload, :invoke, "/2015-03-31/functions/#{function_name}/invocations", [], headers)
client.request(payload, :invoke, data, "/2015-03-31/functions/#{function_name}/invocations", [], headers)
end

def invoke_async(client, function_name, args) do
Logger.info("This API is deprecated. See invoke/5 with the Event value set as invocation type")
client.request(args |> normalize_opts, :invoke, "/2014-11-13/functions/#{function_name}/invoke-async/")
client.request(args |> normalize_opts, :invoke, data, "/2014-11-13/functions/#{function_name}/invoke-async/")
end

def list_event_source_mappings(client, opts \\ []) do
params = opts
|> normalize_opts

client.request(%{}, :list_event_source_mappings, "/2015-03-31/event-source-mappings/", params)
request(client, :list_event_source_mappings, data, "/2015-03-31/event-source-mappings/", params)
end

def list_functions(client, opts \\ []) do
client.request(%{}, :list_functions, "/2015-03-31/functions/", normalize_opts(opts))
request(client, :list_functions, data, "/2015-03-31/functions/", normalize_opts(opts))
end

def remove_permission(client, function_name, statement_id) do
client.request(%{}, :remove_permission, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy/#{statement_id}")
request(client, :remove_permission, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/policy/#{statement_id}")
end

def update_event_source_mapping(client, uuid, attrs_to_update) do
client.request(attrs_to_update, :update_event_source_mapping, "/2015-03-31/event-source-mappings/#{uuid}")
client.request(attrs_to_update, :update_event_source_mapping, data, "/2015-03-31/event-source-mappings/#{uuid}")
end

def update_function_code(client, function_name, zipfile) do
%{"ZipFile" => zipfile}
|> client.request(:update_function_code, "/2015-03-31/functions/#{function_name}/versions/HEAD/code")
request(client, :update_function_code, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/code")
end

def update_function_configuration(client, function_name, configuration) do
client.request(configuration |> normalize_opts, :update_function_configuration, "/2015-03-31/functions/#{function_name}/versions/HEAD/configuration")
client.request(configuration |> normalize_opts, :update_function_configuration, data, "/2015-03-31/functions/#{function_name}/versions/HEAD/configuration")
end

defp normalize_opts(opts) do
Expand Down

0 comments on commit f4eca68

Please sign in to comment.