https://github.com/heiwa4126/sam-stock-trader
同名のAWS SAMのStep Functionsのサンプルテンプレートに、コメントなどをつけていく。学習用。
https://github.com/heiwa4126/sam-stock-trader
aws-sam example stepfunction
Last synced: 4 days ago
JSON representation
同名のAWS SAMのStep Functionsのサンプルテンプレートに、コメントなどをつけていく。学習用。
- Host: GitHub
- URL: https://github.com/heiwa4126/sam-stock-trader
- Owner: heiwa4126
- Created: 2022-03-31T07:57:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-01T04:30:24.000Z (about 4 years ago)
- Last Synced: 2025-02-23T07:16:30.968Z (over 1 year ago)
- Topics: aws-sam, example, stepfunction
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sam-stock-trader
[aws-sam-cli-app-templates/python3.9/cookiecutter-aws-sam-step-functions-sample-app/{{cookiecutter.project_name}} at master · aws/aws-sam-cli-app-templates](https://github.com/aws/aws-sam-cli-app-templates/tree/master/python3.9/cookiecutter-aws-sam-step-functions-sample-app/%7B%7Bcookiecutter.project_name%7D%7D)
にあるAWS SAMのサンプルテンプレートに手をいれたもの。
コードを読みながら、コメントとか入れていく。
ほか参照:
- [AWS SAM を使用して Step Functions ステートマシンを作成 - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/tutorial-state-machine-using-sam.html)
SAMだとASLはYAMLで書ける。便利。
# 動作メモ
起動は
AWS::Events::Rule
で1時間に1回(デプロイ時はdisable)
ASLで最初は
StockCheckerFunction
functions/stock_checker/app.py
もし stock_price が50以下なら
Buy Stock へ。
それ以外は Sell Stock へ。
Buy Stock は
functions/stock_buyer/app.py
Sell Stock は
functions/stock_seller/app.py
で、
Record Transaction で
DynamoDBに入れる。
すごいのはここASLでできること。
# ステートマシンのデプロイ
SAMなので
```sh
sam build
sam deploy --guided # --guidedは2回め以降は不要
```
# ステートマシンの実行
コマンドラインから実行するサンプル `start_statemachine.sh`。
デプロイ成功後、準備として
```sh
pip3 install -U -r requirements.txt
./export1.py
```
を1回実行。
その後
```sh
./start_statemachine.sh
```
でステートマシンが実行される。
# 最適化統合(optimized integrations)
`arn:aws:states:::dynamodb:putItem`
みたいののリファレンスはどこにある?
ここ:
- [Step Functions 用統合最適化 - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/connect-supported-services.html) タイトルから想像できない内容...
- DynamoDBについては [Step Functions を使用した DynamoDB API の呼び出し](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/connect-ddb.html)
統合最適化(optimized integrations)以外の呼び出し方は
[他のサービスで AWS Step Functions を使用する - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/concepts-service-integrations.html)
`arn:aws:states:::aws-sdk:*` を使う
[AWS SDK のサービスの統合 - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/supported-services-awssdk.html)
など。「SDK統合」。いちいちlambdaを書かなくてもいいケースが増える。
# ASLの '$.' とは?
JsonPath。ASL内では使えない関数あり(lenght()とか)
> パスは、JSON テキスト内でコンポーネントを識別するために使用できる $ で始まる文字列です
- [パス - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/amazon-states-language-paths.html)
- [json-path/JsonPath: Java JsonPath implementation](https://github.com/json-path/JsonPath)
- [JSONPath Online Evaluator](https://jsonpath.com/)
# ASLの '.$' とは?
[InputPath、パラメータ、および ResultSelector - AWS Step Functions](https://docs.aws.amazon.com/ja_jp/ja_jp/step-functions/latest/dg/input-output-inputpath-params.html#input-output-parameters)
> パスを使用して値を選択するキーと値のペアの場合、キーの名前は .$ で終わる必要があります。
# ASLの仕様は
ここ: [Amazon States Language](https://states-language.net/)