0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[JAWS-UG CLI] SES:#4 Incoming用ルールセットの有効化、受信テスト (incoming-ses-spam-fileter Python版)

Last updated at Posted at 2016-09-11

前提条件

SESへの権限

SESに対してフル権限があること。

AWS CLI

以下のバージョンで動作確認済

  • AWS CLI 1.10.63
コマンド
aws --version
結果(例)
      aws-cli/1.10.63 Python/2.7.11 Darwin/15.6.0 botocore/1.4.53

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli
  1. 準備
    =======

0.1. リージョンの決定

変数の設定
export AWS_DEFAULT_REGION='us-west-2'

0.2. 変数の確認

プロファイルが想定のものになっていることを確認します。

変数の確認
aws configure list
結果(例)
            Name                    Value             Type    Location
            ----                    -----             ----    --------
         profile       lambdaFull-prjz-mbp13        env    AWS_DEFAULT_PROFILE
      access_key     ****************XXXX shared-credentials-file
      secret_key     ****************XXXX shared-credentials-file
          region        us-west-2        env    AWS_DEFAULT_REGION

0.3. ルールセット名の指定

変数の設定
SES_RULE_SET_NAME='default-rule-set'
  1. 事前作業
    ===========
コマンド
aws ses describe-active-receipt-rule-set 
結果(例)
      (戻り値なし)
  1. ルールセットの有効化
    =======================
変数の確認
cat << ETX

        SES_RULE_SET_NAME: ${SES_RULE_SET_NAME}

ETX
コマンド
aws ses set-active-receipt-rule-set \
        --rule-set-name ${SES_RULE_SET_NAME}
結果(例)
      (戻り値なし)
  1. 事後作業
    ===========

3.1. 有効なルールセットの確認

コマンド
aws ses describe-active-receipt-rule-set 
結果(例)
      {
        "Rules": [
          {
              "Name": "rule-inbound-spam-filter-20160912",
              "Recipients": [
                  "spa@example.org"
              ],
              "Enabled": true,
              "ScanEnabled": true,
              "Actions": [
                  {
                      "LambdaAction": {
                          "InvocationType": "RequestResponse",
                          "FunctionArn": "arn:aws:lambda:us-west-2:XXXXXXXXXXXX:function:inbound-ses-spam-filter-python-20160912"
                      }
                  }
              ],
              "TlsPolicy": "Optional"
          }
        ],
        "Metadata": {
          "CreatedTimestamp": "2016-09-10T01:23:45.678",
          "Name": "default-rule-set"
        }
      }

3.2. メールの受信テスト

コマンド
echo ${SES_RECIPIENT}

メールクライアントから ${SES_RECIPIENT} 宛にテストメールを送信します。

3.3. ログの確認

変数の設定
LOG_GROUP_NAME="/aws/lambda/${LAMBDA_FUNC_NAME}"
TIME_BEFORE_MIN='5'
変数の設定(OSX/BSD系OSの場合)
LOG_START_TIME=$( date -u -v-${TIME_BEFORE_MIN}M '+%s' )000 \
        && echo ${LOG_START_TIME}
変数の設定(Linux系OSの場合)
LOG_START_TIME=$( date -u -d "${TIME_BEFORE_MIN} mins ago" '+%s' )000 \
        && echo ${LOG_START_TIME}
変数の確認
cat << ETX

        LOG_START_TIME: ${LOG_START_TIME}

ETX
コマンド
aws logs filter-log-events \
        --log-group-name ${LOG_GROUP_NAME} \
        --start-time ${LOG_START_TIME}
結果(例)
      [
        {
          "ingestionTime": 1473512559234,
          "timestamp": 1473512559200,
          "message": "START RequestId: d9aaa1cb-7756-11e6-930f-2f1cc5f7b514 Version: $LATESTn",
          "eventId": "32860428129553970586636407428524835670122560352684081152",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        },
        {
          "ingestionTime": 1473512574300,
          "timestamp": 1473512559201,
          "message": "2016-09-10T13:02:39.201053 Starting - inbound-ses-spam-filtern",
          "eventId": "32860428129576271331834938069880484760361662665159737344",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        },
        {
          "ingestionTime": 1473512574300,
          "timestamp": 1473512559201,
          "message": "2016-09-10T13:02:39.201108 Processing message: ebkcbvva9vrb53lhmbjuf2fjmla3v92u0ng70jg1n",
          "eventId": "32860428129576271331834938069880484760361662665159737345",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        },
        {
          "ingestionTime": 1473512574300,
          "timestamp": 1473512559201,
          "message": "2016-09-10T13:02:39.201175 Accepting message: ebkcbvva9vrb53lhmbjuf2fjmla3v92u0ng70jg1n",
          "eventId": "32860428129576271331834938069880484760361662665159737346",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        },
        {
          "ingestionTime": 1473512574300,
          "timestamp": 1473512559207,
          "message": "END RequestId: d9aaa1cb-7756-11e6-930f-2f1cc5f7b514n",
          "eventId": "32860428129710075803026121808729699069997552834195619843",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        },
        {
          "ingestionTime": 1473512574300,
          "timestamp": 1473512559207,
          "message": "REPORT RequestId: d9aaa1cb-7756-11e6-930f-2f1cc5f7b514tDuration: 0.75 mstBilled Duration: 100 ms tMemory Size: 128 MBtMax Memory Used: 43 MBtn",
          "eventId": "32860428129710075803026121808729699069997552834195619844",
          "logStreamName": "2016/09/10/[$LATEST]b90e2350d9c243b0acbbc47e2cc390c4"
        }
      ]

完了

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?