Giter Site home page Giter Site logo

michimani / export-pv-rank Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.74 MB

This is a AWS CDK application that fetch page views from Google Analytics and export ranking data as a JSON file to Amazon S3 bucket.

JavaScript 3.97% Python 66.68% TypeScript 24.72% Shell 4.64%
aws-cdk python typescript google-analytics-api

export-pv-rank's Introduction

export-pv-rank

This is a AWS CDK application that fetch page views from Google Analytics and export ranking data as a JSON file to Amazon S3 bucket.

Features

  • Get report from Google Analytics via Google Analytics Reporting API.
  • Generate PV ranking.
  • Export it as a JSON object to an Amazon S3 bucket.
  • Use Amazon EventBridge scheduling rules to do this on a regular basis.

Architecture

Preparing

Install tools

  • AWS CLI

    $ aws --version
    aws-cli/1.22.82 Python/3.9.10 Darwin/21.4.0 botocore/1.24.27

    Or, version 2.x.

    $ aws --version
    aws-cli/2.4.29 Python/3.8.8 Darwin/21.4.0 exe/x86_64 prompt/off
  • jq

    $ jq --version
    jq-1.6

Generate Google service account key

Generate Google service account key, and export JSON file to the local machine as the name client_secrets.json.

Please see the links below for more information.

Setup project

  1. Clone this repository

    $ git clone https://github.com/michimani/export-pv-rank.git
    $ cd export-pv-rank
  2. Install npm modules

    $ npm install
    ...
  3. Install Python packages

    $ pip3 install --upgrade -r ./lambda/requirements.txt
  4. Create S3 bucket for CDK

    If this is your first time using the CDK in your AWS account and region, run the following command.

    $ cdk bootstrap
  5. Copy client_secrets.json

    Copy the Googel service account key you exported above to the project root directory.

    $ cp /path/to/your/key/client_secrets.json ./
  6. Put Google service accoutn key to SSM parameter store

    $ aws ssm put-parameter \
    --name google-client-secret \
    --type SecureString \
    --value "$(jq -c < ./client_secrets.json)"
  7. Create config file

    $  stack-config.json.sample stack-config.json
    • lambda.env
      • client_secret_ssm_key : SSM parameter store key for Google service account key.
      • view_id : ID of Google Analytics view.
      • out_s3_bucket : S3 bucket name for export PV ranking JSON file. This bucket must already exist.
      • out_json_key : S3 object key for PV ranking JSON.
      • site_base_url : Your site base url. (e.g. https://michimani.net)
    • event_bridge
      • cron_expression : Expression of cron for EventBridge rule.

Run at local

Output PV ranking JSON to standard output.

$ sh ./scripts/run_at_local.sh
Running at local...

Deloying

  1. Create directory for Lambda deploy package

    $ pip3 install --upgrade -r ./lambda/requirements.txt -t ./lambda/dist/ \
    && cp -f ./lambda/src/fetch_rank.py ./lambda/dist/
  2. Generate CloudFormation template

    $ cdk synth
  3. Deploy

    $ cdk deploy

export-pv-rank's People

Contributors

dependabot[bot] avatar michimani avatar

Stargazers

 avatar

Watchers

 avatar  avatar

export-pv-rank's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.