我有一个调用 Lambda 函数来发送电子邮件的 Terraform step_function 脚本。我想将电子邮件的正文作为这样的变量发送:
data "template_file" "start_es_email" {
template = "${file("email_template/start_es.html")}"
}
data "template_file" "start_template" {
template = "${file("step_function/start_stepfunction.json")}"
vars = {
aws_region = "${var.aws_region}",
ses_sender = "${var.ses_sender}"
ses_destination_email = "${var.ses_destination_emails}"
ses_body_html = "${data.template_file.start_es_email.rendered}"
}
}
这是 start_es.html 文件的内容,它只是一个简单的 HTML 内容:
<html>
<body>
<h1>ElasticSearch cluster started and ready</h1>
<p>
The ElasticSearch cluster has started and ready to use
</p>
</body>
</html>
这是状态函数资源:
resource "aws_sfn_state_machine" "start_cluster" {
name = "start-es-sfn-${var.environment}"
role_arn = "${aws_iam_role.step_function_iam_role.arn}"
definition = "${data.template_file.start_template.rendered}"
}
这就是我在状态函数 json 文件中的内容:
"SendSuccessEmail": {
"Type": "Task",
"Resource": "${lambda_notification}",
"Parameters": {
"SES_SENDER": "${ses_sender}",
"SES_DESTINATION_EMAIL": "${ses_destination_email}",
"SUBJECT": "${ses_subject}",
"BODY_HTML": "${ses_body_html}"
},
"End": true
},
现在当调用 terraform apply 我得到这个错误:
错误:InvalidDefinition:无效状态机定义:'INVALID_JSON_DESCRIPTION:非法未引用字符((CTRL-CHAR,代码 10)):必须使用反斜杠转义才能包含在字符串值中
我试图在一行中制作 html 内容:
<html><body><h1>ElasticSearch cluster started and ready</h1><p>The ElasticSearch cluster has started and ready to use</p></body></html>
它工作正常,但这样读取和维护文件并不是很好。
有办法解决吗?
谢谢你。