Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Step FunctionsのLambdaをFargate置換/template化した話

Saito5656
November 20, 2021

Step FunctionsのLambdaをFargate置換/template化した話

2021.11.26のJAWS-UG浜松 AWS勉強会 2021#11でLT予定の資料を登録します。

Saito5656

November 20, 2021
Tweet

More Decks by Saito5656

Other Decks in Programming

Transcript

  1. 今後抽出部分で900秒超過が発生する AWS Cloud User AWS IoT Core IoT hing /

    gateway IoT MQTT protocol Factory Machine Tools Amazon S3 Bucket for summary Bucket for Time line Lambda function to extract Event 0 23 * * * AWS Step Functions workflow Lambda function to summarize Bucket for summarized Bucket for queried IoT rule Bucket for archive IoT topic for Time line IoT topic for summary Life Cycle 2ds RPAで 電子日報に入力 Lambda function to archive TL Event 0 23 * * * AWS Step Functions workflow Lambda function to archive sum CloudFormation Stack CloudFormation Stack
  2. ECS on Fargateへ置換え(見難い・・・) AWS Cloud User AWS IoT Core IoT

    hing / gateway IoT MQTT protocol Factory Machine Tools Amazon S3 Bucket for summary Bucket for Timeline chart Event 0 23 * * * AWS Step Functions workflow Lambda function to summarize Bucket for summarized Bucket for queried IoT rule Bucket for archive IoT topic for Time line IoT topic for summary Life Cycle 2ds RPAで 電子日報に入力 Lambda function to archive TL Event 0 23 * * * AWS Step Functions workflow Lambda function to archive sum VPC Private subnet Amazon ECS AWS Fargate to extract Temporary file CloudFormation Stack CloudFormation Stack Amazon ECR PrivateLink Amazon SQS Amazon EventBridge error⇒SES AWS Step Functions workflow error⇒SES
  3. 今回もSAMを利用 src ┣ build-network-for-ExtOpsFargate ┃ ┣ LineNo.1 ┃ ┣ ext-sum-fargate-{LineName}

    ┃ ┗ ext-docker-{LineName} ┃ ┣ LineNo.2 ┃ ┣ ext-sum-fargate-{LineName} ┃ ┗ ext-docker-{LineName} ┃ ┣ LineNo.3 ┃ ┣ ext-sum-fargate-{LineName} ┃ ┗ ext-docker-{LineName} ┃ VPC/subnet/routetable/sg/endpointを定義 工程1のDockerfileとapp.py 工程1のLambda/Fargate/SFN/Eventを定義 工程2のDockerfileとapp.py 工程2のLambda/Fargate/SFN/Eventを定義 工程3のDockerfileとapp.py 工程3のLambda/Fargate/SFN/Eventを定義 …
  4. NWの構築 src ┣ build-network-for-ExtOpsFargate ┃ ┣ .gitignore ┃ ┣ README.md

    ┃ ┣ samconfig.toml ┃ ┗ template.yaml ┃ template.yaml Parameters CIDR Resources VPC Private subnet SecurityGroup RouteTable VPCEndpoint(ecr.dkr/logs/s3) ecrとlogsはPrivateLink S3はGatewayでVPCと接続
  5. ①前日データを抽出するSFN template.yaml Parameters subnet-id/sg-id/Cpu/Memory Resources Repository Cluster TaskDefinition EcsTaskExecutionRole ExtStateMachine

    StateMachineExecutionRole LogGroup src ┃ ┣ LineNo.1 ┃ ┣ ext-docker-{LineName} ┃ ┃ ┣ app.py ┃ ┃ ┣ Dockerfile ┃ ┃ ┗ requirements.txt ┃ ┣ functions ┃ ┗ ext-sum-fargate-{LineName} ┃ ┣ ExtSumErrorFunc ┃ ┃┣ app.py ┃ ┃┗ requirements.txt ┃ ┣ extstatemachine ┃ ┃┗ sfn.asl.json ┃ ┣ .gitignore ┃ ┣ samconfig.toml ┃ ┗ template.yaml
  6. ②開始終了/稼働/停止を集計するSFN src ┣ LineNo.1 ┃ ┗ ext-sum-fargate-{LineName} ┃ ┣ functions

    ┃ ┃ ┣ SumFunc1 ┃ ┃ ┃ ┣ app.py ┃ ┃ ┃ ┗ requirements.txt ┃ ┃ ┗ ExtSumErrorFunc ┃ ┃ ┣ app.py ┃ ┃ ┗ requirements.txt ┃ ┣ sumstatemachine ┃ ┃┗ sfn.asl.json ┃ ┣ .gitignore ┃ ┣ README.md ┃ ┣ samconfig.toml ┃ ┗ template.yaml template.yaml Parameters Bucket/Prefix Resources Function SumStateMachine StateMachineExecutionRole LogGroup
  7. まとめ 主にやったこと(出来たこと) • vpc/subnet/route table/sg/endpointのCloudFormationテンプレート化 • Task定義のCloudFormationテンプレート化 • statemachine内のTaskをEventBridgeRuleで発火 •

    template.yamlで定義したResourcesへアタッチするroleの細かい定義 主にハマったこと(今後もハマるかも) • Gateway型endpointはroute tableへの紐づけが必要 • Resource IDの呼び出し(!Ref / !Getatt / !SubがTypeで異なる…?) • Propertiesの値をリストで記述する/しない(ちゃんとDoc読めって話) • Statemachineの定義jsonでkeyの一文字目は大文字!!