1

I am trying to receive a message in a queue when triggering an email with SES in localstack. The SES service is using an event destination that connects to a SNS topic. The SNS topic is connected to a queue, where I want to receive the bounce, click information.

Here are the steps:

// 1 whitelist email sender
aws --endpoint-url=http://localhost:4566 ses verify-email-identity --email-address sender@test.com --profile test-profile --region eu-central-1 --output table | cat

// 2 create sqs queue
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name ses_events_queue --profile test-profile --region eu-central-1 --output table | cat

// 3 create sns topic
aws --endpoint-url=http://localhost:4566 sns create-topic --name ses_events_topic --region eu-central-1 --profile test-profile --output table

// 4 subscribe sqs queue to sns topic
aws --endpoint-url=http://localhost:4566 sns subscribe --topic-arn arn:aws:sns:eu-central-1:000000000000:ses_events_topic --protocol sqs --notification-endpoint arn:aws:sqs:eu-central-1:000000000000:ses_events_queue --profile test-profile --region eu-central-1 --output table | cat

up until here, if I publish a message with:

aws --endpoint-url=http://localhost:4566 sns publish --topic-arn arn:aws:sns:eu-central-1:000000000000:ses_events_topic --message "{\"subject\":\"Subject\",\"body8\":\"Body 8\",\"from\":\"test@test.com\",\"to\":\"to@ta.com\"}" --profile test-profile --region eu-central-1 --output table | cat

it works, I can see message in queue.

Now the SES setup:

// 5 create config set
aws --endpoint-url=http://localhost:4566 ses create-configuration-set --configuration-set "{\"Name\":\"ses_config_set\"}" --profile test-profile --region eu-central-1 --output table | cat

// 6 create event destination
aws --endpoint-url=http://localhost:4566 ses create-configuration-set-event-destination --configuration-set-name ses_config_set --event-destination '{"Name":"some_name2","Enabled":true,"MatchingEventTypes":["send","bounce","delivery","open"],"SNSDestination":{"TopicARN":"arn:aws:sns:eu-central-1:000000000000:ses_events_topic"}}' --profile test-profile --region eu-central-1 --output table | cat

And now the actual sending of the email:

// 7 send email via ses using config set
aws --endpoint-url=http://localhost:4566 ses send-email --destination '{"ToAddresses":["receiver@mail.com"]}' --message '{"Subject":{"Data":"some sub","Charset":"string"},"Body":{"Text":{"Data":"some tesxt body","Charset":"string"}}}' --configuration-set-name ses_config_set --from 'sender@test.com' --profile test-profile --region eu-central-1 --output table | cat

Email is sent, but if I check messages in queue, there's none:

aws --endpoint-url=http://localhost:4566 sqs receive-message --queue-url http://localhost:4566/000000000000/ses_events_queue --profile test-profile --region eu-central-1  --output table | cat

Not sure where the error is. I'm also not sure what is the best way to debug. I tried to use --debug in the email sending, but I can't find anything useful.

My suspicion is that the create event destination step can be wrong, since there are may options inside, but not sure.

I've also tried to add permissions to the queue:

aws --endpoint-url=http://localhost:4566 sqs set-queue-attributes --queue-url http://localhost:4566/000000000000/ses_events_queue --attributes file://set_queue_attributes.json --profile test-profile --region eu-central-1 --output table | cat

in set_queue_attributes.json:

{"Policy" : "{\"Id\": \"Policy1564523767951\",\"Version\": \"2012-10-17\",\"Statement\": [{\"Sid\": \"Stmt1564523766749\",\"Action\": \"sqs:*\",\"Effect\": \"Allow\",\"Resource\": \"arn:aws:sqs:us-east-1:12345678:example-queue\",\"Condition\": {\"ArnEquals\": {\"aws:SourceArn\": \"arn:aws:sns:us-east-1:73628827939:MySNS\"}},\"Principal\": \"*\"}]}"}

But it does not work either. Not sure if this might be the issue, because publishing directly to sns, I can see the queue receiving the message. I don't know how to debug, that ses sends the message, and that ses publishes a message in the sns topic

AlbertMunichMar
  • 1,680
  • 5
  • 25
  • 49

2 Answers2

0

In the doc, they state

Whether you create a new SNS topic or select an existing one, you need to give access to SES to publish notifications to the topic.

In your case, try to add this permission, after step 3 //create sns topic

awslocal sns add-permission \
--topic-arn arn:aws:sns:eu-central-1:000000000000:ses_events_topic \
--label Publish-Permission \
--aws-account-id 000000000000 \
--action-name Publish

I use the thin wrapper awslocal

Also, use option "--max-number-of-messages 10" in "sqs receive-message". Default is "1"

Jerome Dh
  • 1
  • 1
  • 3
0

the reason it was not working was because the feature was not implemented. I opened an issue and they worked fast on it: https://github.com/localstack/localstack/issues/7184

I post this answer in case anyone finds something similar

AlbertMunichMar
  • 1,680
  • 5
  • 25
  • 49