How to use templatefile() for a file that exists in s3 for creating sfn definition

Hello, trying to use the resource aws_sfn_state_machine using aws provider, but would like to use a file from s3 in templatefile. Any way around this?

terraform_version: 1.5.7

resource “aws_sfn_state_machine” “sfn_workflow_test” {
definition = templatefile(“file in s3 bucket”, { metric = “Test” })
name = “test-sfn-workflow”
role_arn = “Role ARN”
depends_on =
}

If I try to get this file in s3 into local system using resource local_file, running into an error:

Invalid value for "path" parameter: no file exists at "file in s3 bucket"; this function works only with files that are distributed as part of the configuration source code, so if this file will be created by a resource in this configuration you must instead obtain this result from an attribute of that resource.

You can use aws_s3_object as a source and read your content

data "aws_s3_object" "source" {
  bucket = "bucket"
  key    = "script.txt"
}

resource "aws_sfn_state_machine" "sfn_workflow_test" {
definition = templatefile( data.aws_s3_object.source.body  , { metric = “Test” })
name = "test-sfn-workflow"
role_arn = "Role ARN"
depends_on = []
}

This is throwing an error like Error: Invalid function argument…file name too long.

while calling templatefile(path, vars)
data.aws_s3_object. source.body is Invalid value for "path" parameter: open : file name too long.

nvm, probably need to use templatestring. Thank you!