able to read emails from sqs.
This commit is contained in:
@@ -31,7 +31,8 @@
|
||||
[com.amazonaws/aws-java-sdk-core "1.11.282"]
|
||||
[com.amazonaws/aws-java-sdk-ses "1.11.282"]
|
||||
[com.amazonaws/aws-java-sdk-sqs "1.11.282"]
|
||||
[com.amazonaws/aws-java-sdk-s3 "1.11.282"]]
|
||||
[com.amazonaws/aws-java-sdk-s3 "1.11.282"]
|
||||
[org.clojure/data.json "0.2.6"]]
|
||||
:plugins [[lein-ring "0.9.7"]
|
||||
[lein-cljsbuild "1.1.5"]]
|
||||
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
|
||||
@@ -40,7 +41,8 @@
|
||||
:resource-paths ["resources"]
|
||||
|
||||
:figwheel {:css-dirs ["resources/public/css"]
|
||||
:ring-handler auto-ap.handler/app}
|
||||
:ring-handler auto-ap.handler/app
|
||||
:nrepl-port 7888}
|
||||
|
||||
:aliases {"dev" ["do" "clean"
|
||||
["pdo" ["figwheel" "dev"]]]
|
||||
|
||||
18
src/clj/auto_ap/background/mail.clj
Normal file
18
src/clj/auto_ap/background/mail.clj
Normal file
@@ -0,0 +1,18 @@
|
||||
(ns auto-ap.background.mail
|
||||
(:require [amazonica.aws.sqs :as sqs]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[clojure.data.json :as json])
|
||||
)
|
||||
|
||||
(defn process-sqs []
|
||||
(doseq [message (:messages (sqs/receive-message {:queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod"
|
||||
:wait-time-seconds 5
|
||||
:max-number-of-messages 10
|
||||
#_#_:attribute-names ["All"]}))]
|
||||
(let [message-body (json/read-str (:body message)
|
||||
:key-fn keyword)]
|
||||
(doseq [r (:Records message-body)]
|
||||
(println (-> (s3/get-object {:key (-> r :s3 :object :key)
|
||||
:bucket-name (-> r :s3 :bucket :name)})
|
||||
:input-stream
|
||||
slurp))))))
|
||||
@@ -1,9 +1,11 @@
|
||||
(ns auto-ap.server
|
||||
(:require [auto-ap.handler :refer [app]]
|
||||
[auto-ap.background.mail :refer [process-sqs]]
|
||||
[config.core :refer [env]]
|
||||
[ring.adapter.jetty :refer [run-jetty]])
|
||||
(:gen-class))
|
||||
|
||||
(defn -main [& args]
|
||||
(let [port (Integer/parseInt (or (env :port) "3000"))]
|
||||
(future (process-sqs))
|
||||
(run-jetty app {:port port :join? false})))
|
||||
|
||||
@@ -101,3 +101,6 @@ output "aws_default_region" {
|
||||
value = "us-east-1"
|
||||
}
|
||||
|
||||
output "queue_url" {
|
||||
value = "${aws_sqs_queue.integreat-mail.id}"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"terraform_version": "0.11.5",
|
||||
"serial": 11,
|
||||
"serial": 12,
|
||||
"lineage": "9b630886-8cee-a57d-c7a2-4f19f13f9c51",
|
||||
"modules": [
|
||||
{
|
||||
@@ -23,6 +23,11 @@
|
||||
"sensitive": false,
|
||||
"type": "string",
|
||||
"value": "OtRw2t/xktJBDjP8Jnx1Yf6G+uzBfIkrQEc6nmgo"
|
||||
},
|
||||
"queue_url": {
|
||||
"sensitive": false,
|
||||
"type": "string",
|
||||
"value": "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod"
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
@@ -226,11 +231,11 @@
|
||||
"type": "aws_caller_identity",
|
||||
"depends_on": [],
|
||||
"primary": {
|
||||
"id": "2018-04-06 03:15:18.246075732 +0000 UTC",
|
||||
"id": "2018-04-06 04:15:23.392881567 +0000 UTC",
|
||||
"attributes": {
|
||||
"account_id": "679918342773",
|
||||
"arn": "arn:aws:iam::679918342773:user/bryce",
|
||||
"id": "2018-04-06 03:15:18.246075732 +0000 UTC",
|
||||
"id": "2018-04-06 04:15:23.392881567 +0000 UTC",
|
||||
"user_id": "AIDAJPUJFTOKO4IRADMV4"
|
||||
},
|
||||
"meta": {},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"terraform_version": "0.11.5",
|
||||
"serial": 11,
|
||||
"serial": 12,
|
||||
"lineage": "9b630886-8cee-a57d-c7a2-4f19f13f9c51",
|
||||
"modules": [
|
||||
{
|
||||
@@ -117,6 +117,33 @@
|
||||
"deposed": [],
|
||||
"provider": "provider.aws"
|
||||
},
|
||||
"aws_s3_bucket_notification.mail_bucket_notification": {
|
||||
"type": "aws_s3_bucket_notification",
|
||||
"depends_on": [
|
||||
"aws_s3_bucket.invoices",
|
||||
"aws_sqs_queue.integreat-mail"
|
||||
],
|
||||
"primary": {
|
||||
"id": "integreat-mail-prod",
|
||||
"attributes": {
|
||||
"bucket": "integreat-mail-prod",
|
||||
"id": "integreat-mail-prod",
|
||||
"lambda_function.#": "0",
|
||||
"queue.#": "1",
|
||||
"queue.0.events.#": "1",
|
||||
"queue.0.events.3356830603": "s3:ObjectCreated:*",
|
||||
"queue.0.filter_prefix": "",
|
||||
"queue.0.filter_suffix": "",
|
||||
"queue.0.id": "tf-s3-queue-20180406031531190700000001",
|
||||
"queue.0.queue_arn": "arn:aws:sqs:us-east-1:679918342773:integreat-mail-prod",
|
||||
"topic.#": "0"
|
||||
},
|
||||
"meta": {},
|
||||
"tainted": false
|
||||
},
|
||||
"deposed": [],
|
||||
"provider": "provider.aws"
|
||||
},
|
||||
"aws_ses_receipt_rule.store": {
|
||||
"type": "aws_ses_receipt_rule",
|
||||
"depends_on": [
|
||||
@@ -184,7 +211,7 @@
|
||||
"max_message_size": "262144",
|
||||
"message_retention_seconds": "345600",
|
||||
"name": "integreat-mail-prod",
|
||||
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"sqs:SendMessage\",\"Resource\":\"arn:aws:sqs:*:*:s3-event-notification-queue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:s3:::integreat-mail-prod\"}}}]}",
|
||||
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"sqs:SendMessage\",\"Resource\":\"arn:aws:sqs:*:*:integreat-mail-prod\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:s3:::integreat-mail-prod\"}}}]}",
|
||||
"receive_wait_time_seconds": "0",
|
||||
"tags.%": "0",
|
||||
"visibility_timeout_seconds": "30"
|
||||
@@ -199,11 +226,11 @@
|
||||
"type": "aws_caller_identity",
|
||||
"depends_on": [],
|
||||
"primary": {
|
||||
"id": "2018-04-06 03:12:05.025363179 +0000 UTC",
|
||||
"id": "2018-04-06 03:15:18.246075732 +0000 UTC",
|
||||
"attributes": {
|
||||
"account_id": "679918342773",
|
||||
"arn": "arn:aws:iam::679918342773:user/bryce",
|
||||
"id": "2018-04-06 03:12:05.025363179 +0000 UTC",
|
||||
"id": "2018-04-06 03:15:18.246075732 +0000 UTC",
|
||||
"user_id": "AIDAJPUJFTOKO4IRADMV4"
|
||||
},
|
||||
"meta": {},
|
||||
|
||||
Reference in New Issue
Block a user