0
1

More than 1 year has passed since last update.

Step FunctionsでサポートされたAWSサービスを活用して既存処理の改善するお話

Posted at

はじめに

こんにちは、エキサイト株式会社 SaaS事業部エンジニアの鈴木です。
エキサイトホールディングス Advent Calender 2021の11日目を担当させていただきます。

私事ですがここ2年ほどで衣服を統一してなんちゃってミニマリストとして生活をしています。
不便はないのですが、この時期になると「この服装で去年の冬は越せたから大丈夫だよな・・・」という疑問が湧き上がってくる今日この頃です。
皆様いかがお過ごしでしょうか。

本日の内容

最近Step FunctionsでサポートされるAWSサービスが増えたようなので、
こちらを活用してGlueクローラーで分析用のデータカタログを作成するStep Functionsをbefore/after形式でお届けします。

ワークフロー図

before/afterともに処理の流れは下記の図となります。

stepfunctions_graph.png

なんとなく流れがわかったところで早速ASL

Lambdaで実装(before)

{
  "StartAt": "StartCrawler",
  "States": {
    "StartCrawler": {
      "Type": "Task",
      "Next": "GetCrawler",
      "Parameters": {
        "Name": "snapshot"
      },
      "Resource": "arn:aws:lambda:ap-northeast-1:***:function:StartCrawlerFunction",
      "ResultPath": "$.StartCrawlerResult"
    },
    "GetCrawler": {
      "Type": "Task",
      "Next": "Check crawler status",
      "Parameters": {
        "Name": "snapshot"
      },
      "Resource": "arn:aws:lambda:ap-northeast-1:***:function:GetCrawlerFunction",
      "ResultPath": "$.GetCrawlerResult"
    },
    "Check crawler status": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.GetCrawlerResult.State",
          "StringEquals": "RUNNING",
          "Next": "Wait"
        }
      ],
      "Default": "Other task1"
    },
    "Wait": {
      "Type": "Wait",
      "Seconds": 30,
      "Next": "GetCrawler"
    },
    "Other task1": {
      "Type": "Pass",
      "Next": "Other task2"
    },
    "Other task2": {
      "Type": "Pass",
      "Next": "Succeed"
    },
    "Succeed": {
      "Type": "Succeed"
    }
  }
}

AWSサービスを利用した実装(after)

{
  "StartAt": "StartCrawler",
  "States": {
    "StartCrawler": {
      "Type": "Task",
      "Next": "GetCrawler",
      "Parameters": {
        "Name": "snapshot"
      },
      "Resource": "arn:aws:states:::aws-sdk:glue:startCrawler"
    },
    "GetCrawler": {
      "Type": "Task",
      "Next": "Check crawler status",
      "Parameters": {
        "Name": "snapshot"
      },
      "Resource": "arn:aws:states:::aws-sdk:glue:getCrawler",
      "ResultPath": "$.getCrawler"
    },
    "Check crawler status": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.getCrawler.Crawler.State",
          "StringEquals": "RUNNING",
          "Next": "Wait"
        }
      ],
      "Default": "Other task1"
    },
    "Wait": {
      "Type": "Wait",
      "Seconds": 30,
      "Next": "GetCrawler"
    },
    "Other task1": {
      "Type": "Pass",
      "Next": "Other task2"
    },
    "Other task2": {
      "Type": "Pass",
      "Next": "Succeed"
    },
    "Succeed": {
      "Type": "Succeed"
    }
  }
}

まとめ

今回のシンプルな構成だったためASL上での違いはほぼありませんが、
今までLambdaを作らなければいけなかった箇所がStep Functinosのみで実現できるという部分がとても便利になっているのではないでしょうか。

最後に3行でまとめると
- 最近Step FunctionsでサポートするAWSサービスが増えた
- AWSサービスを活用することで管理下のLambdaを置き換えられる(かもしれない)
- ASLもシンプルになる

以上になります!
ぜひ明日以降のアドベントカレンダーも御覧いただければ幸いです!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1