Skip to content

A json based SNS/SQS configurator for elixir/phoenix projects

License

Notifications You must be signed in to change notification settings

petlove/ex_aws_configurator

Repository files navigation

ExAwsConfigurator

GitHub Workflow Status Coverage Status hex.pm hex.pm hex.pm

Simple json based configurator for AWS SNS/SQS services, use to setup your topics and queues or/and to help to handle topics and queues with prefix or environment based name.

check our documentation

Installation

The package can be installed by adding jason to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_aws_configurator, "~> 1.4"}
  ]
end

Configuring ExAws

that package use ExAws to make requests to AWS, you will must to set ex_aws configuration into your config file to:

config :ex_aws,
  access_key_id: "<AWS_ACCESS_KEY_ID>",
  secret_access_key: "<AWS_SECRET_ACCESS_KEY>"

alternatively, you can set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY on your system environment, see ExAws for more.

Configuring ExAwsConfigurator

look for the config.exs example above:

config :ex_aws_configurator,
  account_id: "000000000000",
  queues: %{
    an_queue: %{
      environment: "an_environment",
      prefix: "queue_prefix",
      region: "us-east-1",
      topics: [:an_topic]
    },
    # ...
  },
  topics: %{
    an_topic: %{environment: "an_environment", prefix: "prefix", region: "us-east-1"},
    another_topic: %{},
    # ...
  }

assuming prod environment, when run ExAwsConfigurator.setup() will:

  1. create queue named queue_prefix_an_environment_an_queue on us-east-1 AWS region
  2. create topic named prefix_an_environment_an_topic on us-east-1 AWS region
  3. create topic named prod_another_topic on default AWS region
  4. subscribe queue queue_prefix_an_environment_an_queue into topic prefix_an_environment_an_topic

queue and topic name composition is: prefix + environment + key joined by _.

Name Default Required Description
account_id nil true your AWS account id, this is used to calculate topic/queue arn
queues [] true list of queues configuration
topics [] true list of topic configuration
environment Mix.env() no current environment, this is used to compose topic/queue name, use nil to skip
prefix nil no Used to compose topic/queue name.
region System.get_env("AWS_REGION") no use to specify aws region or to override ex_aws default region
topics [] no list of topics that the queue will subscribe to, must be an atom and the topic must be specified on topics list

if you prefer more control on topics and queues criation you can use create/subscribe methods separately

ExAwsConfigurator.SQS.create_queue(:an_queue)

ExAwsConfigurator.SQS.subscribe(:an_topic, :an_queue)

PS: keys MUST be present on config.exs to work correctly.

this package provide some helpers to publish or send message too, for complete use please, check our documentation

Contributing

feel free to contribute, issues and pull requests are welcome

License

The MIT License (MIT)

Copyright (c) 2014-2020 CargoSense, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.