LoginSignup
9
3

More than 5 years have passed since last update.

Amazon Pinpointをモバイルアプリに導入して、とりあえずプッシュ通知が送れるようになるまで:AWS編

Posted at

この記事は iRidge Advent Calendar 2018 の20日目です。

はじめに

Amazon Pinpointを導入してAndroidアプリへプッシュ配信を実装するまでを書いていきます。
今回はAWSのセットアップ方法を解説していきます。アプリの実装については21日目の記事を参照してください。

Pinpointとは

Pinpointはアプリユーザーに対してEメールやプッシュ通知を送信することができるサービスになります。
配信速度の設定や開封率の分析、A/Bテストなども可能です。
公式ドキュメントは以下になります。
https://aws.amazon.com/jp/pinpoint/features/?nc=nsb&pg=ln

Pinpointのセットアップ

はじめにAWSマネジメントコンソールにログインして、Pinpointのコンソール画面を開きます。

プロジェクト名を決めて、 Create a project ボタンをクリックします。
Pinpointはまだ東京リージョンで利用できないので、バージニアリージョンで作成します。

pinpoint1.png

プロジェクトを作成すると、設定画面に遷移します。
今回はPush通知を送信することがゴールなので、 Push notifications を選択します。

pinpoint2.png

設定画面ではモバイルプッシュおよびWebプッシュを設定することができます。
Endpoints には各プラットフォームへの組み込み方法が記載されています。

pinpoint3.png

Androidアプリへのプッシュ通知を実装するので、FirebaseのサーバーキーをPinpointに設定します。

pinpoint4.png

設定が完了すると Firebase Cloud Messaging の項目が Enabled になります。

pinpoint5.png

アプリはCognito identity poolに対して認証を行い、イベントの生成やエンドポイントの登録を行うので、Cognito identity poolを作成します。

pinpoint6.png

適当なIDプール名を設定します。今回の認証プロバイダーにはCoginito user poolを設定しました。

pinpoint7.png

作成したらCognitoにIAMポリシーを設定します。設定するポリシーは以下になります。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobiletargeting:PutEvents"
      ],
      "Resource": [
        "arn:aws:mobiletargeting:us-east-1:xxx:apps/xxx"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
          "mobiletargeting:UpdateEndpoint"
      ],
      "Resource": [
          "arn:aws:mobiletargeting:us-east-1:xxx:apps/xxx"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
          "mobileanalytics:PutEvents"
      ],
      "Resource": [
          "*"
      ]
    }
  ]
}

ポリシーを反映したらこれまでの設定を awsconfiguration.json にまとめてアプリに連携します。

awsconfiguration.json

         {
             "Version": "1.0",
             "CredentialsProvider": {
                 "CognitoIdentity": {
                     "Default": {
                         "PoolId": "xxx",
                         "Region": "us-east-1"
                     }
                 }
             },
             "IdentityManager" : {
               "Default" : {

               }
             },
             "PinpointAnalytics": {
                 "Default": {
                   "AppId": "xxx",
                   "Region": "us-east-1"
                 }
               },
             "PinpointTargeting": {
               "Default": {
                 "Region": "us-east-1"
               }
             }
         }

まとめ

アプリにプッシュ通知を配信するためのAmazon Pinpointの設定を行いました。
今後はアナリティクスなどの機能も試してみたいです。

最後に

今回の作業はアイリッジのエンジニア制度の一つであるFryhigh Fridayを活用しました。
詳しくは4日目の記事を参考にしてください。

9
3
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
9
3