CreateLogGroup & Use it at execution in Step Function

0

When we create / define a Step Function, we can associate it to a CloudWatch Log Group. But, if I want to create a LogGroup itself as part of Step Function and use that for Step Function logging, will it be possible? If yes, please provide an example.

2回答
0
承認された回答

Hi,

No, unfortunately it is no possible. According to AWS documentation, you can set the LoggingConfiguration parameter when using UpdateStateMachine, but running executions will continue to use the previous definition and roleArn.

You can check it yourself with the following example that I have prepared. Starting from a Step Function with logging disabled, in the first state a loggroup is created and in the second its own configuration is updated to enable logging on said loggroup. Thus, although both actions are executed correctly, the execution is not logged.

{
  "Comment": "A description of my state machine",
  "StartAt": "CreateLogGroup",
  "States": {
    "CreateLogGroup": {
      "Type": "Task",
      "Next": "UpdateStateMachine",
      "Parameters": {
        "LogGroupName": "MyTestLogGroup"
      },
      "Resource": "arn:aws:states:::aws-sdk:cloudwatchlogs:createLogGroup"
    },
    "UpdateStateMachine": {
      "Type": "Task",
      "Parameters": {
        "StateMachineArn.$": "$$.StateMachine.Id",
        "LoggingConfiguration": {
          "Destinations": [
            {
              "CloudWatchLogsLogGroup": {
                "LogGroupArn": "arn:aws:logs:<region>:<account-number>:log-group:MyTestLogGroup:*"
              }
            }
          ],
          "IncludeExecutionData": true,
          "Level": "ALL"
        }
      },
      "Resource": "arn:aws:states:::aws-sdk:sfn:updateStateMachine",
      "Next": "LogOutput"
    },
    "LogOutput": {
      "Type": "Pass",
      "End": true,
      "Result": {
        "result": "OK"
      }
    }
  }
}
profile picture
エキスパート
回答済み 1年前
profile picture
エキスパート
レビュー済み 1ヶ月前
0

Hello,

The usecase is not at all feasible since, even if the State Machine keeps updating the log group provided in the definition, running executions will continue to use the previous definition and role Arn exclusively.

According to AWS documentation, it is mentioned that to configure logging, you can pass the LoggingConfiguration parameter when using CreateStateMachine or UpdateStateMachine.

I further verified the setup at my end using the example below and found that, while the step function creates a new log group, the logs will only appear in the previous log groups as stated in the previous definition.

You can check it yourself as mentioned with the following example given. Starting from a Step Function with logging disabled, in the first state a log group is created and in the second its own configuration is updated to enable logging on said log group. Thus, although both actions are executed correctly, the execution is not logged and you will see the logs in the previous defined Log group rather than the current one that you mention in the running execution.

{
  "Comment": "A description of my state machine",
  "StartAt": "CreateLogGroup",
  "States": {
    "CreateLogGroup": {
      "Type": "Task",
      "Next": "UpdateStateMachine",
      "Parameters": {
        "LogGroupName": "MyTestLogGroup"
      },
      "Resource": "arn:aws:states:::aws-sdk:cloudwatchlogs:createLogGroup"
    },
    "UpdateStateMachine": {
      "Type": "Task",
      "Parameters": {
        "StateMachineArn.$": "$$.StateMachine.Id",
        "LoggingConfiguration": {
          "Destinations": [
            {
              "CloudWatchLogsLogGroup": {
                "LogGroupArn": "arn:aws:logs:<region>:<account-number>:log-group:MyTestLogGroup:*"
              }
            }
          ],
          "IncludeExecutionData": true,
          "Level": "ALL"
        }
      },
      "Resource": "arn:aws:states:::aws-sdk:sfn:updateStateMachine",
      "Next": "LogOutput"
    },
    "LogOutput": {
      "Type": "Pass",
      "End": true,
      "Result": {
        "result": "OK"
      }
    }
  }
}

Thanks

Anmol
回答済み 10ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ