LoginSignup
0
0

More than 1 year has passed since last update.

【AWS CloudFormation】serverless.templateを利用してインフラをコード化してみた。

Last updated at Posted at 2021-09-20

はじめに

毎日定期的に通知を送る処理をEventBridge + Lambdaで作成したのですが、CloudFormationの勉強として、それらをserverless.templateにまとめてみました。

参考にしたドキュメント

AWSの公式ドキュメントを参考にしました。

serverless.template

serverless.template
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Transform": "AWS::Serverless-2016-10-31",
  "Description": "An AWS Serverless Application.",
  "Resources": {
    "ScrapingApp": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "FunctionName": "ScrapingApp",
        "Description": "サイトのスクレイピング結果をメールで送信します。",
        "Handler": "ScrapingApp::ScrapingApp.Program::Main",
        "Runtime": "dotnetcore3.1",
        "MemorySize": 128,
        "Timeout": 300,
        "Role": "適切なロール",
        "Policies": [
          "role-lambdaBasic"
        ],
        "Events":{ 
            "EventBridge" : {
                "Type" : "Schedule",
                "Properties" : {
                    "Schedule" : "cron(0 22,8 * * ? *)",
                    "Name": "ScrapingAppEventBridge",
                    "Description": "ScrapingApp関数のトリガーです。"
                }
            }
        }
      }
    }
  }
}

ハマったポイント

EventBridgeの部分のTypeを"EventBridgeRule"としていました。
そちらのPattern内の設定でいけるかと思ったのですが、うまくイベントが発火せず...。
よくよく調べると"Schedule"というTypeを見つけて、そちらを利用するとしっかり発火してくれました。

まだまだ知らないことばかりですが、少しずつ調べて理解できるように頑張ります。

0
0
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
0