Search code examples
elixirphoenix-frameworkamazon-cloudfront

How create invalidation in aws cloudfront after action in my elixir/phoenix project


I use the ex_aws dependency in my elixir/phoenix project to make some actions in my aws account. Now I need to run something like this to invalidate the cache:

aws cloudfront create-invalidation --distribution-id 1111111111 --paths '/*'

But the ex_aws dependency doesn't have the cloudfront service. Any solutions for this?

Versions:
      {:phoenix, "~> 1.4.0"}
      ...
      {:ex_aws, "~> 2.1.0"},
      {:ex_aws_s3, "~> 2.0.1"},

Solution

  • You should not try to cover all the functionality AWS provides via pure Elixir wrappers. Erlang (and hence Elixir) both are built to maintain a very good interaction level with the underlying OS and System.cmd/3 is the first class citizen. So,

    System.cmd(
      "aws",
      ~w|cloudfront create-invalidation --distribution-id 1111111111 --paths '/*'|,
      env: [{"MIX_ENV", "prod"}])