PlugPubsub
This proyect implements ExAws.SNS to publish messages to an AWS SNS Topic and ExAws.SQS to cconsume messages sent to AWS SQS, in Elixir.
Folder structure
.
├── config
│ └── config.exs
├── lib
│ ├── application.ex
│ ├── consumer.ex
│ └── plug_pubsub.ex
├── mix.exs
├── mix.lock
├── README.md
└── test
├── plug_pubsub_test.exs
└── test_helper.exs
Dependencies
Configurable parameters
First of all, you need to configure a SNS topic and you need to configure a SNS topic in AWS. Once you have the ARN, the mandatory environment variables to configure are:
$ export AWS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/{account_id}/{queue_name}
$ export AWS_TOPIC_ARN=arn:aws:sns:us-east-1:{account_id}:{topic_name}
For local tests, you need to create a security credentials and then set the following enviroment variables:
$ export AWS_SECRET_ACCESS_KEY={user_account_secret_access}
$ export AWS_ACCESS_KEY_ID={user_account_access_key}
If you deploy the module on a AWS Server, it will take the instance role configuration as a credential to publish and consume messages.
Installation
If available in Hex, the package can be installed
by adding plug_pubsub to your list of dependencies in mix.exs:
def deps do
[
{:plug_pubsub, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/plug_pubsub.
How to use
To use, just open a console and use the method AwsPublisher.publish_message:
AwsPublisher.publish_message("Some title", %{"age" => 44, "name" => "Jhon Doe", "nationality" => "Colombian"})