Skip to content

Create pre-signed CloudFront resource URLs based on S3 private content

License

Notifications You must be signed in to change notification settings

qstream/cloudfront-signer

 
 

Repository files navigation

CloudfrontSigner

Elixir implementation of Cloudfront's url signature algorithm. Supports expiration policies and runtime configurable distributions.

Installation

If available in Hex, the package can be installed by adding cloudfront_signer to your list of dependencies in mix.exs:

def deps do
  [
    {:cloudfront_signer, "~> 0.3.0"}
  ]
end

Configure a distribution with:

config :my_app, :my_distribution,
  domain: "https://some.cloudfront.domain",
  private_key: {:system, "ENV_VAR"}, # or {:file, "/path/to/key"}
  key_pair_id: {:system, "OTHER_ENV_VAR"}

Then simply do:

CloudfrontSigner.Distribution.from_config(:my_app, :my_distribution)
|> CloudfrontSigner.sign(path, [arg: "value"], expiry_in_seconds)

If you want to cache pem decodes (which is a wise choice), a registry of decoded distributions is available. Simply do:

CloudfrontSigner.DistributionRegistry.get_distribution(:my_app, :my_distribution)
|> CloudfrontSigner.sign(path, [arg: "value], expiry)

By default it uses Poison, but you can specify a different JSON processor such as Jason by setting this in your config.exs:

config :cloudfront_signer, :json_codec, Jason

About

Create pre-signed CloudFront resource URLs based on S3 private content

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Elixir 99.5%
  • Shell 0.5%