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.
.
├── config
│ └── config.exs
├── lib
│ ├── application.ex
│ ├── consumer.ex
│ └── aws_pubsub.ex
├── mix.exs
├── mix.lock
├── README.md
└── test
├── aws_pubsub_test.exs
└── test_helper.exs
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.
If available in Hex, the package can be installed by adding aws_pubsub
to your list of dependencies in mix.exs
:
def application do
[
applications: [:hackney]
]
end
def deps do
[
{:aws_pubsub, "~> 0.1.0", runtime: false}
]
end
This configuration is only to use the publisher, because I still working on the consumer to work on the package. You will also need to, manually set the config parameters on config.exs:
use Mix.Config
config :aws_pubsub,
queue_url: System.get_env("AWS_QUEUE_URL"),
publish_topic_arn: System.get_env("AWS_TOPIC_ARN")
config :ex_aws,
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role],
region: [System.get_env("AWS_REGION"), "us-east-1"]
Documentation docs can be found at https://hexdocs.pm/aws_pubsub.
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"})