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.

已提问 1 年前475 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则