SES SMTP Credentials


今天在設定新的 SES 的時候遇到設定 SMTP Credentials 和 IAM Policy 權限的問題。

問題

第一次在 SES Console 設定時,到 SMTP 頁面指定產生一組 Credentials,然後就用這 Credential 到 AWS CLI 做 sendmail 驗證,結果一直出現以下訊息:

A client error (SignatureDoesNotMatch) occurred when calling the CreateInvalidation operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

過程猜測過幾個可能:

  1. AWS CLI 版本太舊,所以更新到最新版
  2. 環境太髒,換一台機器
  3. 以為建立 Credential 時,要用它指定的 IAM User 名稱,格式大概是 ses-smtp-xxxxx,所以又重產好幾次
  4. 以為是 CLI 下錯了
  5. 以為使用的 region 有問題,又換另一個 region,從 us-west-2 換到 us-west-1

就這樣搞了一個多小時 ….

後來才發現 官方文件 針對 Credentials 這樣描述:

There are different types of credentials, and the credentials you use depend on what you want to do. For example, you use AWS access keys when you send an email using the Amazon SES API, and SMTP credentials when you send an email using the Amazon SES SMTP interface.

意思是說,使用 SES API 和 SMTP credentials 是不一樣的,也就在 SES Console -> SMTP 產生的這組 Key 會用來給 SMTP Client 做身份認證;而使用 AWS CLI/SDK 則要使用 IAM Access Key 或者 IAM Role.

結論

新增的 SES 幾個要注意的地方:

  1. 預設的 SES 是在 Sandbox mode,一天只能送 200 封信,同時 sender / receiver 都要經過驗證,是為了要避免被當作垃圾信的來源。
  2. SMTP Credentials 和 AWS CLI / SDK Access Key 是不一樣的。

Reference



Comments

  • 全站索引
  • 關於這裏
  • 關於作者
  • 學習法則
  • 思考本質
  • 一些領悟
  • 分類哲學
  • ▲ TOP ▲