From 0188a88dcb2964fadf317c7da8d788dad80edbea Mon Sep 17 00:00:00 2001 From: Cees de Groot Date: Tue, 16 Jan 2024 17:43:41 -0500 Subject: [PATCH 1/3] Attempt to make the create_function call a bit more flexible --- lib/ex_aws/lambda.ex | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/ex_aws/lambda.ex b/lib/ex_aws/lambda.ex index 0476b59..389e80b 100644 --- a/lib/ex_aws/lambda.ex +++ b/lib/ex_aws/lambda.ex @@ -105,27 +105,37 @@ defmodule ExAws.Lambda do Create a function. Runtime defaults to nodejs, as that is the only one available. + + If options contains `package_type`, then if that is "Image" the function creates + a container function; else it will create a zipfile-based function. For a container, + the `handler` argument will be ignored. """ @spec create_function( function_name :: binary, handler :: binary, - zipfile :: binary + zipfile_or_container_uri :: binary ) :: ExAws.Operation.JSON.t() @spec create_function( function_name :: binary, handler :: binary, - zipfile :: binary, + zipfile_or_container_uri :: binary, opts :: create_function_opts ) :: ExAws.Operation.JSON.t() - def create_function(function_name, handler, zipfile, opts \\ []) do + def create_function(function_name, handler, zipfile_or_container_uri, opts \\ []) do + code = + if opts[:package_type] == "Image" do + %{"Code" => %{"ImageURI" => zipfile_or_container_uri}} + else + %{"Code" => %{"ZipFile" => zipfile_or_container_uri}, "Handler" => handler} + end + data = opts |> normalize_opts |> Map.merge(%{ "FunctionName" => function_name, - "Handler" => handler, - "Code" => %{"ZipFile" => zipfile} }) + |> Map.merge(code) request(:create_function, data, "/2015-03-31/functions") end From 0e624486b6c59e4d74cc967f8b2b35268c57c59b Mon Sep 17 00:00:00 2001 From: Cees de Groot Date: Wed, 17 Jan 2024 15:48:19 -0500 Subject: [PATCH 2/3] Fix capitalization of ImageUri argument --- lib/ex_aws/lambda.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ex_aws/lambda.ex b/lib/ex_aws/lambda.ex index 389e80b..7acb1ec 100644 --- a/lib/ex_aws/lambda.ex +++ b/lib/ex_aws/lambda.ex @@ -124,7 +124,7 @@ defmodule ExAws.Lambda do def create_function(function_name, handler, zipfile_or_container_uri, opts \\ []) do code = if opts[:package_type] == "Image" do - %{"Code" => %{"ImageURI" => zipfile_or_container_uri}} + %{"Code" => %{"ImageUri" => zipfile_or_container_uri}} else %{"Code" => %{"ZipFile" => zipfile_or_container_uri}, "Handler" => handler} end From 57cd9fbeadca2fd4dc76084d5b7f456d1d9b2e72 Mon Sep 17 00:00:00 2001 From: Cees de Groot Date: Mon, 22 Jan 2024 09:13:52 -0500 Subject: [PATCH 3/3] Mix format --- lib/ex_aws/lambda.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ex_aws/lambda.ex b/lib/ex_aws/lambda.ex index 7acb1ec..f43ea67 100644 --- a/lib/ex_aws/lambda.ex +++ b/lib/ex_aws/lambda.ex @@ -133,7 +133,7 @@ defmodule ExAws.Lambda do opts |> normalize_opts |> Map.merge(%{ - "FunctionName" => function_name, + "FunctionName" => function_name }) |> Map.merge(code)