【问题标题】:Sending email via SES in localstack, with an event destination with a sns topic, not working在 localstack 中通过 SES 发送电子邮件,事件目的地带有 sns 主题,不工作
【发布时间】:2023-02-14 03:18:04
【问题描述】:

在 localstack 中使用 SES 触发电子邮件时,我试图在队列中接收消息。 SES 服务正在使用连接到 SNS 主题的事件目标。 SNS 主题连接到一个队列,我想在其中接收退回、点击信息。

以下是步骤:

// 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

到这里为止,如果我发布一条消息:

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

它有效,我可以在队列中看到消息。

现在 SES 设置:

// 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

现在实际发送电子邮件:

// 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

电子邮件已发送,但如果我检查队列中的邮件,则没有:

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

不确定错误在哪里。我也不确定什么是最好的调试方法。我试图在电子邮件发送中使用--debug,但我找不到任何有用的东西。

我怀疑create event destination步骤可能是错误的,因为里面可能有选项,但不确定。

我还尝试向队列添加权限:

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

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\": \"*\"}]}"}

但它也不起作用。不确定这是否是问题所在,因为直接发布到sns,我可以看到queue 收到消息。我不知道如何调试,ses 发送消息,sessns 主题中发布消息

【问题讨论】:

    标签: aws-cli localstack


    【解决方案1】:

    In the doc,他们说

    无论您是创建新的 SNS 主题还是选择现有主题,您都需要授予 SES 访问权限以向该主题发布通知。

    在您的情况下,尝试在步骤 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
    

    我用薄包装纸awslocal

    此外,在“sqs receive-message”中使用选项“--max-number-of-messages 10”。 默认为“1”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 2019-05-04
      • 2016-04-08
      • 2020-06-11
      • 2016-11-17
      • 2013-02-21
      相关资源
      最近更新 更多