Skip to content

ysano/twitter-dashboard

Repository files navigation

Tweet Analytics

1 About

  • 指定 Timeline の Tweet の分析をする(感情など)
  • AWS 上で構築する

2 構成図

./fig.png

3 手順

3.1 Twitter Developer Platform で App 作成

Twitter Developer Platform で App を作る。

  • Access token
  • Access token secret

審査があるので説明は詳しく書く。

3.2 データストアを作る

3.2.1 AWS S3 bucket を作る

  • raw
  • sentiment
  • entities

3.2.2 AWS Kinesis Data Firehose 用 IAM Policy&Role 作成

  • Policy: Tweet-Dashboard-Firehose
    • S3 bucket の List,Read,Write Action
    • CloudWatch Logs の List,Write Action
  • Role: Tweet-Dashboard-Firehose-Policy

3.2.3 AWS Kinesis Data Firehose の作成

  • Create Delivery Stream in {raw/,sentiment/,entities/}
    • Tweet-Dashboard-$prefix とする
    • S3 bucket ARN + prefix: $prefix
    • Buffer conditions: Interval 60sec

3.2.4 AWS Secrets Manager に Twitter App の secret を設定

  • TwitteAPI-Secrets を Generate する
    • ConsumerApiKey
    • ConsumerApiSecret
    • AccessToken
    • AccessTokenSecret

3.2.5 AWS CloudFormation で VPC を作成

3.2.6 AWS EC2 にて Instance 作成

  • Spec
    • t4g.nano
  • 設定
    • npm init
    • npm install aws-sdk twitter-lite
  • node twitter_reader.js を systemd で回す
    • /etc/systemd/system に twrd.service を配置
    • systemctl enable twrd
    • systemctl start twrd
  • S3 bucket raw/ にデータが溜まっていく

3.3 分析システムを構築

3.3.1 AWS Lambda 用 IAM 作成

  • TweetAnalysisLambdaFunctionRole
  • TweetAnalysisLambdaFunctionPolicy
  • lambda_iam.yaml

3.3.2 AWS Lambda

  • lambda_function.py
    • S3 bucket を Comprehend にわたす
    • Delivery Stream Name については SENTIMENT_STREAM, ENTITY_STREAM 環境変数にて渡
  • TweetAnalysisLambdaFunctionRole をつける
  • Timeout 5min
  • S3 bucket sentiment, entities に結果が蓄積される

3.4 可視化

3.4.1 AWS Glue にて Metadata catalog 作成

  • 動的フレーム作成(Spark と違い初期 Schema 不要)
  • glue_table.yaml
  • Database: twitter_timeline_dashboard
    • tweets
    • tweet_sentiments
    • tweet_entities

3.4.2 Amazon Athena でクエリ実行

  • s3://twitter_timeline_dashboard/
select * from tweet_sentiments limit 10;
select * from tweet_entities limit 10;

3.4.3 Amazon QuickSight

  • S3 bucket を選択
  • 分析を作成

About

Tweet感情分析DashboradをAWSで構築する

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors