https://github.com/ryosukedtomita/ocn_daily_login_aws_lambda
OCNの訪問ログインをseleniumで自動化する。(AWS版)
https://github.com/ryosukedtomita/ocn_daily_login_aws_lambda
aws-lambda chromium-headless cloudformation iac python3 selenium
Last synced: about 1 month ago
JSON representation
OCNの訪問ログインをseleniumで自動化する。(AWS版)
- Host: GitHub
- URL: https://github.com/ryosukedtomita/ocn_daily_login_aws_lambda
- Owner: RyosukeDTomita
- License: unlicense
- Created: 2023-08-04T09:43:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-24T01:00:56.000Z (over 1 year ago)
- Last Synced: 2025-03-10T18:53:47.962Z (over 1 year ago)
- Topics: aws-lambda, chromium-headless, cloudformation, iac, python3, selenium
- Language: Python
- Homepage: https://www.ocn.ne.jp/
- Size: 643 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# INDEX
- [ABOUT](#ABOUT)
- [ENVIRONMENT](#ENVIRONMENT)
- [PREPARING](#PREPARING)
- [HOW TO USE](#HOW-TO-USE)
- [REFERENCE](#REFERENCE)
******
# ABOUT

- Using selenium, push [ocn top page](https://www.ocn.ne.jp/) "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](./create_cookies.py) locally and uploaded to S3 beforehand.

******
# ENVIRONMENT
- python 3.7 (chromium-headless supported version)
- [headless-chromium-amazonlinux-2017-03](https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-55/stable-headless-chromium-amazonlinux-2017-03.zip)
- [chromedriver_linux64](https://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip)
see [requirements.txt](./requirements.txt)
******
# PREPARING
## Common
### AWS CLI
- Create AWS IAM Users for AWS CLI and attached `AdministratorAcess`.
- [install aws cli](https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/getting-started-install.html)
- create ~/.aws/config and paste AccessKey, SecretAccessKey.
```
# ~/.aws/config
[profile default]
region = ap-northeast-1
aws_access_key_id = <>
aws_secret_access_key = <>
```
- check connection
```shell
aws sts get-caller-identity
```
### python(venv)
```shell
# 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
```shell
# 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
```shell
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](https://docs.aws.amazon.com/ja_jp/serverless-application-model/latest/developerguide/install-sam-cli.html)
1. download zip
2. unzip
3. install
4. check
```shell
# install command
sudo ./sam-installation/install
sam --version
```
### build and deploy
```shell
sam build
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
```
```shell
sam delete # delete stack
```
If you want to use GUI, see [README_gui.md](./docs/README_gui.md)
**For developer**, you can only deploy IAM Role and S3 for the first deploy.
```shell
# only initial deploy
sam build -t ./template_s3iam.yaml
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
```
```shell
# 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.
```shell
python3 create_cookies.py --userid --password --bucket --profile
```
- Then, every 01:00 AM, EventBridge call lambda function and push OCN daily login button.
:warning: If you want to just reupload `cookies.pkl`, you can use aws cli.
```shell
aws s3 cp cookies.pkl s3://cookie-for-iceman2 --acl private --profile=default
```