Skip to content

Commit

Permalink
invoke lambda function in pixel handler for #35
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 7, 2020
1 parent 6396591 commit 46d1c5d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/app_web/controllers/sent_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ defmodule AppWeb.SentController do
end

def pixel(conn, _params) do
# warm up the lambda function so emails are sent instantly!
payload = %{"ping" => :os.system_time(:millisecond), key: "ping"}
# IO.inspect(payload, label: "payload ping/2:151")
# see: https://github.com/dwyl/elixir-invoke-lambda-example
lambda = System.get_env("AWS_LAMBDA_FUNCTION")
ExAws.Lambda.invoke(lambda, payload, "no_context")
|> ExAws.request(region: System.get_env("AWS_REGION"))
|> IO.inspect(label: "ExAws.Lambda ping response")

conn # instruct browser not to cache the image
|> put_resp_header("cache-control", "no-store, private")
|> put_resp_header("pragma", "no-cache")
Expand Down

0 comments on commit 46d1c5d

Please sign in to comment.