Skip to content

RyosukeDTomita/ocn_daily_login_aws_lambda

Repository files navigation

INDEX


ABOUT

template

  • Using selenium, push ocn top page "OCN訪問ポイント" button automatically to get Dpoint.
  • OCN site has two factor authentication, but AWS Lambda cannot get SMS Auhentication PIN when running.
  • That's why, this Lambda use prepared cookies.pkl to login.
  • cookies.pkl must have been created by create_cookies.py locally and uploaded to S3 beforehand.

ocn訪問ポイント


ENVIRONMENT


PREPARING

Common

AWS CLI

  • Create AWS IAM Users for AWS CLI and attached AdministratorAcess.
  • install aws cli
  • create ~/.aws/config and paste AccessKey, SecretAccessKey.
# ~/.aws/config
[profile default]
region = ap-northeast-1
aws_access_key_id = <<IAM AccessKey>>
aws_secret_access_key = <<IAM SecretAccessKey>>
  • check connection
aws s3 ls --profile gr360

python(venv)

# install python3.7
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
 
# install python3.7 venv
sudo apt install python3.7-venv
 
# create python3.7 venv
python3.7 -m venv ~/ocn_daily_login
source ~/ocn_daily_login/bin/activate # activate venv

clone this repository and set up

# download repository
git clone https://github.com:RyosukeDTomita/ocn_dialy_login_aws_lambda.git

# set up
cd ocn_dialy_login_aws_lambda
pip -r requirements.txt

Download headless-chromeium and driver

cd ./create_selenium_driver_layers
source mk_driver_lib_layer.sh
ls create_selenium_driver_layers/headless
chromedriver*  headless-chromium*  locales/

Use CloudFormation

AWS SAM settings

how to install

  1. download zip
  2. unzip
  3. install
  4. check
# install command
sudo ./sam-installation/install
sam --version

build and deploy

sam build
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
sam delete # delete stack

If you want to use GUI, see README_gui.md

For developer, you can only deploy IAM Role and S3 for the first deploy.

# only initial deploy
sam build -t ./template_s3iam.yaml
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
# skip deploy S3 and IAM Role
sam build -t template_dev.yaml
sam deploy --guided

Note Do not use -t in sam deploy If you use, python library(boto3 and seleniumA) do not deploy with lambda and No module name Error occured.


HOW TO USE

  • create cookies.pkl and upload to S3.
python3 create_cookies.py --userid <docomo userid> --password <password> --bucket <bucket-name> --profile <aws cli profile>
  • Then, every 01:00 AM, EventBridge call lambda function and push OCN daily login button.

⚠️ If you want to just reupload cookies.pkl, you can use aws cli.

aws s3 cp cookies.pkl s3://cookie-for-iceman2 --acl private --profile=default

Releases

No releases published

Packages

No packages published